<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Date::Pcalc - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Date-Pcalc - MetaCPAN" href="https://metacpan.org/dist/Date-Pcalc/releases.rss" />
        <link rel="canonical" href="./Date::Pcalc.html" />
        <meta name="description" content="Calendar objects for different holiday schemes" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Date::Pcalc" />
<meta name="twitter:title"       content="Date::Pcalc" />
<meta name="twitter:description" content="" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Date::Pcalc.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Date-Pcalc was released.">
      <span class="relatize">16 Oct 2009 05:54:08 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Date-Pcalc">Date-Pcalc</a>
  </li>
  <li>
    Module version: 6.1
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Date-Pcalc/source/src/Perl/Pcalc.pm">Source</a>
    (<a href="https://metacpan.org/dist/Date-Pcalc/source/src/Perl/Pcalc.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g p" href="https://metacpan.org/dist/Date-Pcalc/source/Pcalc.pod">Pod Source</a>
    (<a href="https://metacpan.org/dist/Date-Pcalc/source/Pcalc.pod?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Date-Pcalc/source/src/Perl">Browse</a>
    (<a href="https://metacpan.org/dist/Date-Pcalc/source/src/Perl?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Date-Pcalc/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Date-Pcalc/contribute">How to Contribute</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Date-Pcalc">Issues</a>
      (6)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Date-Pcalc+6.1" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Date-Pcalc.html?oncpan=1&amp;distmat=1&amp;version=6.1&amp;grade=2" style="color: #090">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Date-Pcalc.html?oncpan=1&amp;distmat=1&amp;version=6.1&amp;grade=3" style="color: #900">2</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Date-Pcalc.html?oncpan=1&amp;distmat=1&amp;version=6.1&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/STBEY/Date-Pcalc-6.1">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Date-Pcalc who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 0
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Date-Pcalc-6.1/index.html">% Coverage </a>
    </li>
    <li>
      License: unknown
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Date-Pcalc/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/S/ST/STBEY/Date-Pcalc-6.1.tar.gz">
      Download (<span itemprop="fileSize">211.71KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FSTBEY%2FDate-Pcalc-6.1%2Fsrc%2FPerl%2FPcalc.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Date-Pcalc/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Date-Pcalc/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Date-Pcalc">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Date-Pcalc">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/src/Perl/Pcalc.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  
  value="DLAMBLEY/Date-Pcalc-6.2"
>6.2
  (DLAMBLEY on 2021-04-23)</option>
<option
  disabled
  value="STBEY/Date-Pcalc-6.1"
>6.1
  (STBEY on 2009-10-16)</option>
<option
  
  value="STBEY/Date-Pcalc-6.0"
>6.0
  (STBEY on 2009-10-08)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Date-Pcalc-1.2"
>1.2
  (STBEY on 2001-04-10)</option>
<option
  
  value="STBEY/Date-Pcalc-1.1"
>1.1
  (STBEY on 2001-03-17)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/STBEY/Date-Pcalc-6.1/diff/' + encodeURIComponent(this.value) + '/src/Perl/Pcalc.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  
  value="DLAMBLEY/Date-Pcalc-6.2"
>6.2
  (DLAMBLEY on 2021-04-23)</option>
<option
  disabled
  value="STBEY/Date-Pcalc-6.1"
>6.1
  (STBEY on 2009-10-16)</option>
<option
  
  value="STBEY/Date-Pcalc-6.0"
>6.0
  (STBEY on 2009-10-08)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Date-Pcalc-1.2"
>1.2
  (STBEY on 2001-04-10)</option>
<option
  
  value="STBEY/Date-Pcalc-1.1"
>1.1
  (STBEY on 2001-03-17)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="./Bit::Vector.html" title="Bit::Vector" class="ellipsis">Bit::Vector</a></li>
  <li><a href="./Carp::Clan.html" title="Carp::Clan" class="ellipsis">Carp::Clan</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Date::Pcalc/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Date%3A%3APcalc">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Date-Pcalc">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/STBEY/Date-Pcalc-6.1/view/src/Perl/Pcalc.pm">This version</a>
    </li>
    <li>
      <a href="./Date::Pcalc.html">Latest version</a>
    </li>
    <li>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/STBEY" class="author-name">Steffen Beyer</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/src/Perl/Pcalc.pm&#39;" class="">
<option
  
  value="DLAMBLEY/Date-Pcalc-6.2"
>6.2
  (DLAMBLEY on 2021-04-23)</option>
<option
  selected
  value="STBEY/Date-Pcalc-6.1"
>6.1
  (STBEY on 2009-10-16)</option>
<option
  
  value="STBEY/Date-Pcalc-6.0"
>6.0
  (STBEY on 2009-10-08)</option>
<optgroup label="BackPAN">'
<option
  
  value="STBEY/Date-Pcalc-1.2"
>1.2
  (STBEY on 2001-04-10)</option>
<option
  
  value="STBEY/Date-Pcalc-1.1"
>1.1
  (STBEY on 2001-03-17)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Date-Pcalc">Date-Pcalc-6.1</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage one &#10;
          • 1 direct dependent &#10;          • 1 total dependent
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Date-Pcalc-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Date-Pcalc-6.1">
    <input type="hidden" name="author" value="STBEY">
    <input type="hidden" name="distribution" value="Date-Pcalc">
    <button type="submit" class="favorite"><span></span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Date::Pcalc.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite">
<span></span> ++</a>
</div>
   / <span>Date::Pcalc</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Date::Pcalc.html#NAME">NAME</a></li>
  <li><a href="./Date::Pcalc.html#MOTTO">MOTTO</a></li>
  <li><a href="./Date::Pcalc.html#PREFACE">PREFACE</a></li>
  <li><a href="./Date::Pcalc.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Date::Pcalc.html#IMPORTANT-NOTES">IMPORTANT NOTES</a></li>
  <li><a href="./Date::Pcalc.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Date::Pcalc.html#RECIPES">RECIPES</a></li>
  <li><a href="./Date::Pcalc.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Date::Pcalc.html#BEWARE">BEWARE</a></li>
  <li><a href="./Date::Pcalc.html#VERSION">VERSION</a></li>
  <li><a href="./Date::Pcalc.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Date::Pcalc.html#COPYRIGHT">COPYRIGHT</a></li>
  <li><a href="./Date::Pcalc.html#LICENSE">LICENSE</a></li>
  <li><a href="./Date::Pcalc.html#DISCLAIMER">DISCLAIMER</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Date::Pcalc - Gregorian calendar date calculations</p>

<h1 id="MOTTO">MOTTO</h1>

<p>Keep it small, fast and simple</p>

<h1 id="PREFACE">PREFACE</h1>

<p>This package consists of a library written in pure Perl providing all sorts of date calculations based on the Gregorian calendar (the one used in all western countries today), thereby complying with all relevant norms and standards: <span style="white-space: nowrap;">ISO/R 2015-1971</span>, <span style="white-space: nowrap;">DIN 1355</span> and, to some extent, <span style="white-space: nowrap;">ISO 8601</span> (where applicable).</p>

<p>(See also http://www.engelschall.com/u/sb/download/Date-Calc/DIN1355/ for a scan of part of the &quot;<span style="white-space: nowrap;">DIN 1355</span>&quot; document (in German)).</p>

<p>This package is meant as a drop-in replacement for <a href="http://man.he.net/man3/Date::Calc">Date::Calc(3)</a>, the latter of which is written in C and XS and therefore needs a C compiler in order to build and install (which this one doesn&#39;t).</p>

<p>The module of course handles year numbers of 2000 and above correctly (&quot;Year 2000&quot; or &quot;Y2K&quot; compliance) -- actually all year numbers from 1 to the largest positive integer representable on your system (which is at least 32767) can be dealt with.</p>

<p>This is not true, however, for the import/export functions in this package which are an interface to the internal POSIX date and time functions of your system, which can only cover dates in the following ranges:</p>

<pre><code> 01-Jan-1970 00:00:00 GMT .. 19-Jan-2038 03:14:07 GMT [Unix etc.]
 01-Jan-1904 00:00:00 LT  .. 06-Feb-2040 06:28:15 LT  [MacOS Classic]
 (LT = local time)</code></pre>

<p>Note that this package projects the Gregorian calendar back until the year <span style="white-space: nowrap;">1 A.D.</span> -- even though the Gregorian calendar was only adopted in 1582, mostly by the Catholic European countries, in obedience to the corresponding decree of Pope <span style="white-space: nowrap;">Gregory XIII</span> in that year.</p>

<p>Some (mainly protestant) countries continued to use the Julian calendar (used until then) until as late as the beginning of the 20th century.</p>

<p>Finally, note that this package is not intended to do everything you could ever imagine automagically for you; it is rather intended to serve as a toolbox (in the best of UNIX spirit and traditions) which should, however, always get you where you want to go.</p>

<p>See the section &quot;RECIPES&quot; at the bottom of this document for solutions to common problems!</p>

<p>If nevertheless you can&#39;t figure out how to solve a particular problem, please let me know! (See e-mail address at the end of this document.)</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>  use Date::Pcalc qw(
      Days_in_Year
      Days_in_Month
      Weeks_in_Year
      leap_year
      check_date
      check_time
      check_business_date
      Day_of_Year
      Date_to_Days
      Day_of_Week
      Week_Number
      Week_of_Year
      Monday_of_Week
      Nth_Weekday_of_Month_Year
      Standard_to_Business
      Business_to_Standard
      Delta_Days
      Delta_DHMS
      Delta_YMD
      Delta_YMDHMS
      N_Delta_YMD
      N_Delta_YMDHMS
      Normalize_DHMS
      Add_Delta_Days
      Add_Delta_DHMS
      Add_Delta_YM
      Add_Delta_YMD
      Add_Delta_YMDHMS
      Add_N_Delta_YMD
      Add_N_Delta_YMDHMS
      System_Clock
      Today
      Now
      Today_and_Now
      This_Year
      Gmtime
      Localtime
      Mktime
      Timezone
      Date_to_Time
      Time_to_Date
      Easter_Sunday
      Decode_Month
      Decode_Day_of_Week
      Decode_Language
      Decode_Date_EU
      Decode_Date_US
      Fixed_Window
      Moving_Window
      Compress
      Uncompress
      check_compressed
      Compressed_to_Text
      Date_to_Text
      Date_to_Text_Long
      English_Ordinal
      Calendar
      Month_to_Text
      Day_of_Week_to_Text
      Day_of_Week_Abbreviation
      Language_to_Text
      Language
      Languages
      Decode_Date_EU2
      Decode_Date_US2
      Parse_Date
      ISO_LC
      ISO_UC
  );

  use Date::Pcalc qw(:all);

  Days_in_Year
      $days = Days_in_Year($year,$month);

  Days_in_Month
      $days = Days_in_Month($year,$month);

  Weeks_in_Year
      $weeks = Weeks_in_Year($year);

  leap_year
      if (leap_year($year))

  check_date
      if (check_date($year,$month,$day))

  check_time
      if (check_time($hour,$min,$sec))

  check_business_date
      if (check_business_date($year,$week,$dow))

  Day_of_Year
      $doy = Day_of_Year($year,$month,$day);

  Date_to_Days
      $days = Date_to_Days($year,$month,$day);

  Day_of_Week
      $dow = Day_of_Week($year,$month,$day);

  Week_Number
      $week = Week_Number($year,$month,$day);          # DEPRECATED

  Week_of_Year
      ($week,$year) = Week_of_Year($year,$month,$day); # RECOMMENDED
      $week = Week_of_Year($year,$month,$day);         # DANGEROUS

  Monday_of_Week
      ($year,$month,$day) = Monday_of_Week($week,$year);

  Nth_Weekday_of_Month_Year
      if (($year,$month,$day) =
      Nth_Weekday_of_Month_Year($year,$month,$dow,$n))

  Standard_to_Business
      ($year,$week,$dow) =
      Standard_to_Business($year,$month,$day);

  Business_to_Standard
      ($year,$month,$day) =
      Business_to_Standard($year,$week,$dow);

  Delta_Days
      $Dd = Delta_Days($year1,$month1,$day1,
                       $year2,$month2,$day2);

  Delta_DHMS
      ($Dd,$Dh,$Dm,$Ds) =
      Delta_DHMS($year1,$month1,$day1, $hour1,$min1,$sec1,
                 $year2,$month2,$day2, $hour2,$min2,$sec2);

  Delta_YMD
      ($Dy,$Dm,$Dd) =
      Delta_YMD($year1,$month1,$day1,
                $year2,$month2,$day2);

  Delta_YMDHMS
      ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) =
      Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1,
                   $year2,$month2,$day2, $hour2,$min2,$sec2);

  N_Delta_YMD
      ($Dy,$Dm,$Dd) =
      N_Delta_YMD($year1,$month1,$day1,
                  $year2,$month2,$day2);

  N_Delta_YMDHMS
      ($D_y,$D_m,$D_d, $Dhh,$Dmm,$Dss) =
      N_Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1,
                     $year2,$month2,$day2, $hour2,$min2,$sec2);

  Normalize_DHMS
      ($Dd,$Dh,$Dm,$Ds) =
      Normalize_DHMS($Dd,$Dh,$Dm,$Ds);

  Add_Delta_Days
      ($year,$month,$day) =
      Add_Delta_Days($year,$month,$day,
                     $Dd);

  Add_Delta_DHMS
      ($year,$month,$day, $hour,$min,$sec) =
      Add_Delta_DHMS($year,$month,$day, $hour,$min,$sec,
                     $Dd,$Dh,$Dm,$Ds);

  Add_Delta_YM
      ($year,$month,$day) =
      Add_Delta_YM($year,$month,$day,
                   $Dy,$Dm);

  Add_Delta_YMD
      ($year,$month,$day) =
      Add_Delta_YMD($year,$month,$day,
                    $Dy,$Dm,$Dd);

  Add_Delta_YMDHMS
      ($year,$month,$day, $hour,$min,$sec) =
      Add_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec,
                       $D_y,$D_m,$D_d, $Dh,$Dm,$Ds);

  Add_N_Delta_YMD
      ($year,$month,$day) =
      Add_N_Delta_YMD($year,$month,$day,
                      $Dy,$Dm,$Dd);

  Add_N_Delta_YMDHMS
      ($year,$month,$day, $hour,$min,$sec) =
      Add_N_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec,
                         $D_y,$D_m,$D_d, $Dhh,$Dmm,$Dss);

  System_Clock
      ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) =
      System_Clock([$gmt]);

  Today
      ($year,$month,$day) = Today([$gmt]);

  Now
      ($hour,$min,$sec) = Now([$gmt]);

  Today_and_Now
      ($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]);

  This_Year
      $year = This_Year([$gmt]);

  Gmtime
      ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) =
      Gmtime([time]);

  Localtime
      ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) =
      Localtime([time]);

  Mktime
      $time = Mktime($year,$month,$day, $hour,$min,$sec);

  Timezone
      ($D_y,$D_m,$D_d, $Dh,$Dm,$Ds, $dst) = Timezone([time]);

  Date_to_Time
      $time = Date_to_Time($year,$month,$day, $hour,$min,$sec);

  Time_to_Date
      ($year,$month,$day, $hour,$min,$sec) = Time_to_Date([time]);

  Easter_Sunday
      ($year,$month,$day) = Easter_Sunday($year);

  Decode_Month
      if ($month = Decode_Month($string[,$lang]))

  Decode_Day_of_Week
      if ($dow = Decode_Day_of_Week($string[,$lang]))

  Decode_Language
      if ($lang = Decode_Language($string))

  Decode_Date_EU
      if (($year,$month,$day) = Decode_Date_EU($string[,$lang]))

  Decode_Date_US
      if (($year,$month,$day) = Decode_Date_US($string[,$lang]))

  Fixed_Window
      $year = Fixed_Window($yy);

  Moving_Window
      $year = Moving_Window($yy);

  Compress
      $date = Compress($year,$month,$day);

  Uncompress
      if (($century,$year,$month,$day) = Uncompress($date))

  check_compressed
      if (check_compressed($date))

  Compressed_to_Text
      $string = Compressed_to_Text($date[,$lang]);

  Date_to_Text
      $string = Date_to_Text($year,$month,$day[,$lang]);

  Date_to_Text_Long
      $string = Date_to_Text_Long($year,$month,$day[,$lang]);

  English_Ordinal
      $string = English_Ordinal($number);

  Calendar
      $string = Calendar($year,$month[,$orthodox[,$lang]]);

  Month_to_Text
      $string = Month_to_Text($month[,$lang]);

  Day_of_Week_to_Text
      $string = Day_of_Week_to_Text($dow[,$lang]);

  Day_of_Week_Abbreviation
      $string = Day_of_Week_Abbreviation($dow[,$lang]);

  Language_to_Text
      $string = Language_to_Text($lang);

  Language
      $lang = Language();
      Language($lang);               # DEPRECATED
      $oldlang = Language($newlang); # DEPRECATED

  Languages
      $max_lang = Languages();

  Decode_Date_EU2
      if (($year,$month,$day) = Decode_Date_EU2($string[,$lang]))

  Decode_Date_US2
      if (($year,$month,$day) = Decode_Date_US2($string[,$lang]))

  Parse_Date
      if (($year,$month,$day) = Parse_Date($string[,$lang]))

  ISO_LC
      $lower = ISO_LC($string);

  ISO_UC
      $upper = ISO_UC($string);

  Version
      $string = Date::Pcalc::Version();</code></pre>

<h1 id="IMPORTANT-NOTES"><a id="IMPORTANT"></a>IMPORTANT NOTES</h1>

<p>(See the section &quot;RECIPES&quot; at the bottom of this document for solutions to common problems!)</p>

<ul>

<li><p>&quot;Year 2000&quot; (&quot;Y2K&quot;) compliance</p>

<p>The upper limit for any year number in this module is only given by the size of the largest positive integer that can be represented in a scalar variable on your system, which is at least 32767, according to the ANSI C standard, on which Perl is based (exceptions see below).</p>

<p>In order to simplify calculations, this module projects the gregorian calendar back until the year <span style="white-space: nowrap;">1 A.D.</span> -- i.e., back <b>BEYOND</b> the year 1582 when this calendar was first decreed by the Catholic Pope <span style="white-space: nowrap;">Gregory XIII</span>!</p>

<p>Therefore, <b>BE SURE TO ALWAYS SPECIFY &quot;1998&quot; WHEN YOU MEAN &quot;1998&quot;</b>, for instance, and <b>DO NOT WRITE &quot;98&quot; INSTEAD</b>, because this will in fact perform a calculation based on the year &quot;98&quot; A.D. and <b>NOT</b> &quot;1998&quot;!</p>

<p>An exception from this rule are the functions which contain the word &quot;compress&quot; in their names (which can only handle years between 1970 and 2069 and also accept the abbreviations &quot;00&quot; to &quot;99&quot;), and the functions whose names begin with &quot;Decode_Date_&quot; (which translate year numbers below 100 using a technique known as &quot;moving window&quot;).</p>

<p>If you want to convert a two-digit year number into a full-fledged, four-digit (at least for some years to come <code>;-)</code>) year number, use the two functions &quot;Fixed_Window()&quot; and &quot;Moving_Window()&quot; (see their description further below).</p>

<p>Note also that the following import/export functions (which are interfaces to the POSIX functions &quot;time()&quot;, &quot;gmtime()&quot;, &quot;localtime()&quot; and &quot;mktime()&quot; or (the last two) substitutes for the BSD function &quot;timegm()&quot; and the POSIX function &quot;gmtime()&quot;) have a very limited range of representable dates (in contrast to all other functions in this package, which cover virtually any date including and after <span style="white-space: nowrap;">January 1st 1 A.D.</span>):</p>

<pre><code>              System_Clock()
              Today()
              Now()
              Today_and_Now()
              This_Year()
              Gmtime()
              Localtime()
              Mktime()
              Timezone()
              Date_to_Time()
              Time_to_Date()</code></pre>

<p>These functions can only deal with dates in the range from <span style="white-space: nowrap;">01-Jan-1970 00:00:00 GMT</span> to <span style="white-space: nowrap;">19-Jan-2038 03:14:07 GMT</span> (the latter limit is only authoritative on <span style="white-space: nowrap;">32 bit</span> systems, however, and can (in principle, through a few code changes) be extended somewhat <code>:-)</code> on <span style="white-space: nowrap;">64 bit</span> systems).</p>

<p>On MacOS Classic, the valid range of dates is between (both included) <span style="white-space: nowrap;">01-Jan-1904 00:00:00</span> (local time) to <span style="white-space: nowrap;">06-Feb-2040 06:28:15</span> (local time).</p>

<p>Note further that the function &quot;Easter_Sunday()&quot; can only be used for years in the range 1583 to 2299.</p>

</li>
<li><p>POSIX functions</p>

<p>Note that the following functions</p>

<pre><code>              Gmtime()
              Localtime()
              Mktime()
              Timezone()</code></pre>

<p>are actually wrappers around or based upon the corresponding POSIX functions &quot;time()&quot;, &quot;gmtime()&quot;, &quot;localtime()&quot; and &quot;mktime()&quot;.</p>

<p>As such, they depend on local settings of the underlying machine such as e.g. the system clock, the time zone and the locale.</p>

<p>Their results can therefore sometimes be unexpected or counter-intuitive.</p>

<p>Therefore, no support can be provided for these functions.</p>

<p>They are supplied &quot;as is&quot;, purely for the sake of interoperability.</p>

<p>Use at your own risk. (You have been warned!)</p>

</li>
<li><p>First index</p>

<p><b>ALL</b> ranges in this module start with &quot;<code>1</code>&quot;, <b>NOT</b> &quot;<code>0</code>&quot;!</p>

<p>I.e., the day of month, day of week, day of year, month of year, week of year, first valid year number and language <b>ALL</b> start counting at one, <b>NOT</b> zero!</p>

<p>The only exception is the function &quot;<code>Week_Number()</code>&quot;, which may in fact return &quot;<code>0</code>&quot; when the given date actually lies in the last week of the <b>PREVIOUS</b> year, and of course the numbers for hours (<code>0..23</code>), minutes (<code>0..59</code>) and seconds (<code>0..59</code>).</p>

</li>
<li><p>Function naming conventions</p>

<p>Function names completely in lower case indicate a boolean return value.</p>

</li>
<li><p>Boolean values</p>

<p>Boolean values returned from functions in this module are always a numeric zero (&quot;<code>0</code>&quot;) for &quot;false&quot; and a numeric one (&quot;<code>1</code>&quot;) for &quot;true&quot;.</p>

</li>
<li><p>Exception handling</p>

<p>The functions in this module will usually die with a corresponding error message if their input parameters, intermediate results or output values are out of range.</p>

<p>The following functions handle errors differently:</p>

<pre><code>  -  check_date()
  -  check_time()
  -  check_business_date()
  -  check_compressed()</code></pre>

<p>(which return a &quot;false&quot; return value when the given input does not represent a valid date or time),</p>

<pre><code>  -  Nth_Weekday_of_Month_Year()</code></pre>

<p>(which returns an empty list if the requested 5th day of week does not exist),</p>

<pre><code>  -  Decode_Month()
  -  Decode_Day_of_Week()
  -  Decode_Language()
  -  Fixed_Window()
  -  Moving_Window()
  -  Compress()</code></pre>

<p>(which return &quot;<code>0</code>&quot; upon failure or invalid input), and</p>

<pre><code>  -  Decode_Date_EU()
  -  Decode_Date_US()
  -  Decode_Date_EU2()
  -  Decode_Date_US2()
  -  Parse_Date()
  -  Uncompress()</code></pre>

<p>(which return an empty list upon failure or invalid input).</p>

<p>Note that you can always catch an exception thrown by any of the functions in this module and handle it yourself by enclosing the function call in an &quot;<code>eval</code>&quot; with curly brackets and checking the special variable &quot;<code>$@</code>&quot; (see <a href="http://man.he.net/man1/perlfunc">&quot;eval&quot; in perlfunc(1)</a> for details).</p>

</li>
</ul>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<ul>

<li><p><code>use Date::Pcalc qw( Days_in_Year Days_in_Month ... );</code></p>

</li>
<li><p><code>use Date::Pcalc qw(:all);</code></p>

<p>You can either specify the functions you want to import explicitly by enumerating them between the parentheses of the &quot;<code>qw()</code>&quot; operator, or you can use the &quot;<code>:all</code>&quot; tag instead to import <b>ALL</b> available functions.</p>

</li>
<li><p><code>$days = Days_in_Year($year,$month);</code></p>

<p>This function returns the sum of the number of days in the months starting with January up to and including &quot;<code>$month</code>&quot; in the given year &quot;<code>$year</code>&quot;.</p>

<p>I.e., &quot;<code>Days_in_Year(1998,1)</code>&quot; returns &quot;<code>31</code>&quot;, &quot;<code>Days_in_Year(1998,2)</code>&quot; returns &quot;<code>59</code>&quot;, &quot;<code>Days_in_Year(1998,3)</code>&quot; returns &quot;<code>90</code>&quot;, and so on.</p>

<p>Note that &quot;<code>Days_in_Year($year,12)</code>&quot; returns the number of days in the given year &quot;<code>$year</code>&quot;, i.e., either &quot;<code>365</code>&quot; or &quot;<code>366</code>&quot;.</p>

</li>
<li><p><code>$days = Days_in_Month($year,$month);</code></p>

<p>This function returns the number of days in the given month &quot;<code>$month</code>&quot; of the given year &quot;<code>$year</code>&quot;.</p>

<p>The year must always be supplied, even though it is only needed when the month is February, in order to determine whether it is a leap year or not.</p>

<p>I.e., &quot;<code>Days_in_Month(1998,1)</code>&quot; returns &quot;<code>31</code>&quot;, &quot;<code>Days_in_Month(1998,2)</code>&quot; returns &quot;<code>28</code>&quot;, &quot;<code>Days_in_Month(2000,2)</code>&quot; returns &quot;<code>29</code>&quot;, &quot;<code>Days_in_Month(1998,3)</code>&quot; returns &quot;<code>31</code>&quot;, and so on.</p>

</li>
<li><p><code>$weeks = Weeks_in_Year($year);</code></p>

<p>This function returns the number of weeks in the given year &quot;<code>$year</code>&quot;, i.e., either &quot;<code>52</code>&quot; or &quot;<code>53</code>&quot;.</p>

</li>
<li><p><code>if (leap_year($year))</code></p>

<p>This function returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given year &quot;<code>$year</code>&quot; is a leap year and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

</li>
<li><p><code>if (check_date($year,$month,$day))</code></p>

<p>This function returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given three numerical values &quot;<code>$year</code>&quot;, &quot;<code>$month</code>&quot; and &quot;<code>$day</code>&quot; constitute a valid date, and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

</li>
<li><p><code>if (check_time($hour,$min,$sec))</code></p>

<p>This function returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given three numerical values &quot;<code>$hour</code>&quot;, &quot;<code>$min</code>&quot; and &quot;<code>$sec</code>&quot; constitute a valid time (<code>0 &lt;= $hour &lt; 24</code>, <code>0 &lt;= $min &lt; 60</code> and <code>0 &lt;= $sec &lt; 60</code>), and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

</li>
<li><p><code>if (check_business_date($year,$week,$dow))</code></p>

<p>This function returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given three numerical values &quot;<code>$year</code>&quot;, &quot;<code>$week</code>&quot; and &quot;<code>$dow</code>&quot; constitute a valid date in business format, and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

<p><b>Beware</b> that this function does <b>NOT</b> compute whether a given date is a business day (i.e., Monday to Friday)!</p>

<p>To do so, use &quot;<code>(Day_of_Week($year,$month,$day) &lt; 6)</code>&quot; instead.</p>

</li>
<li><p><code>$doy = Day_of_Year($year,$month,$day);</code></p>

<p>This function returns the (relative) number of the day of the given date in the given year.</p>

<p>E.g., &quot;<code>Day_of_Year($year,1,1)</code>&quot; returns &quot;<code>1</code>&quot;, &quot;<code>Day_of_Year($year,2,1)</code>&quot; returns &quot;<code>32</code>&quot;, and &quot;<code>Day_of_Year($year,12,31)</code>&quot; returns either &quot;<code>365</code>&quot; or &quot;<code>366</code>&quot;.</p>

<p>The day of year is sometimes also referred to as the Julian day (or date), although it has nothing to do with the Julian calendar, the calendar which was used before the Gregorian calendar.</p>

<p>In order to convert the number returned by this function back into a date, use the function &quot;<code>Add_Delta_Days()</code>&quot; (described further below), as follows:</p>

<pre><code>  $doy = Day_of_Year($year,$month,$day);
  ($year,$month,$day) = Add_Delta_Days($year,1,1, $doy - 1);</code></pre>

</li>
<li><p><code>$days = Date_to_Days($year,$month,$day);</code></p>

<p>This function returns the (absolute) number of the day of the given date, where counting starts at the 1st of January of the year <span style="white-space: nowrap;">1 A.D.</span></p>

<p>I.e., &quot;<code>Date_to_Days(1,1,1)</code>&quot; returns &quot;<code>1</code>&quot;, &quot;<code>Date_to_Days(1,12,31)</code>&quot; returns &quot;<code>365</code>&quot;, &quot;<code>Date_to_Days(2,1,1)</code>&quot; returns &quot;<code>366</code>&quot;, &quot;<code>Date_to_Days(1998,5,1)</code>&quot; returns &quot;<code>729510</code>&quot;, and so on.</p>

<p>This is sometimes also referred to (not quite correctly) as the Julian date (or day). This may cause confusion, because also the number of the day in a year (from 1 to 365 or 366) is frequently called the &quot;Julian day&quot;.</p>

<p>More confusing still, this has nothing to do with the Julian calendar, which was used <b>BEFORE</b> the Gregorian calendar.</p>

<p>The Julian calendar was named after famous Julius Caesar, who had instituted it in Roman times. The Julian calendar is less precise than the Gregorian calendar because it has too many leap years compared to the true mean length of a year (but the Gregorian calendar also still has one day too much every 5000 years). Anyway, the Julian calendar was better than what existed before, because rulers had often changed the calendar used until then in arbitrary ways, in order to lengthen their own reign, for instance.</p>

<p>In order to convert the number returned by this function back into a date, use the function &quot;<code>Add_Delta_Days()</code>&quot; (described further below), as follows:</p>

<pre><code>  $days = Date_to_Days($year,$month,$day);
  ($year,$month,$day) = Add_Delta_Days(1,1,1, $days - 1);</code></pre>

</li>
<li><p><code>$dow = Day_of_Week($year,$month,$day);</code></p>

<p>This function returns the number of the day of week of the given date.</p>

<p>The function returns &quot;<code>1</code>&quot; for Monday, &quot;<code>2</code>&quot; for Tuesday and so on until &quot;<code>7</code>&quot; for Sunday.</p>

<p>Note that in the Hebrew calendar (on which the Christian calendar is based), the week starts with Sunday and ends with the Sabbath or Saturday (where according to the Genesis (as described in the Bible) the Lord rested from creating the world).</p>

<p>In medieval times, Catholic Popes have decreed the Sunday to be the official day of rest, in order to dissociate the Christian from the Hebrew belief.</p>

<p>It appears that this actually happened with the Emperor Constantin, who converted to Christianity but still worshipped the Sun god and therefore moved the Christian sabbath to the day of the Sun.</p>

<p>Nowadays, the Sunday <b>AND</b> the Saturday are commonly considered (and used as) days of rest, usually referred to as the &quot;week-end&quot;.</p>

<p>Consistent with this practice, current norms and standards (such as <span style="white-space: nowrap;">ISO/R 2015-1971</span>, <span style="white-space: nowrap;">DIN 1355</span> and <span style="white-space: nowrap;">ISO 8601</span>) define the Monday as the first day of the week.</p>

</li>
<li><p><code>$week = Week_Number($year,$month,$day);</code></p>

<p>This function returns the number of the week the given date lies in.</p>

<p>If the given date lies in the <b>LAST</b> week of the <b>PREVIOUS</b> year, &quot;<code>0</code>&quot; is returned.</p>

<p>If the given date lies in the <b>FIRST</b> week of the <b>NEXT</b> year, &quot;<code>Weeks_in_Year($year) + 1</code>&quot; is returned.</p>

</li>
<li><p><code>($week,$year) = Week_of_Year($year,$month,$day);</code></p>

<p>This function returns the number of the week the given date lies in, as well as the year that week belongs to.</p>

<p>I.e., if the given date lies in the <b>LAST</b> week of the <b>PREVIOUS</b> year, &quot;<code>(Weeks_in_Year($year-1), $year-1)</code>&quot; is returned.</p>

<p>If the given date lies in the <b>FIRST</b> week of the <b>NEXT</b> year, &quot;<code>(1, $year+1)</code>&quot; is returned.</p>

<p>Otherwise, &quot;<code>(Week_Number($year,$month,$day), $year)</code>&quot; is returned.</p>

</li>
<li><p><code>$week = Week_of_Year($year,$month,$day);</code></p>

<p>In scalar context, this function returns just the week number. This allows you to write &quot;<code>$week = Week_of_Year($year,$month,$day);</code>&quot; instead of &quot;<code>($week) = Week_of_Year($year,$month,$day);</code>&quot; (note the parentheses around &quot;<code>$week</code>&quot;).</p>

<p>If the given date lies in the <b>LAST</b> week of the <b>PREVIOUS</b> year, &quot;<code>Weeks_in_Year($year-1)</code>&quot; is returned.</p>

<p>If the given date lies in the <b>FIRST</b> week of the <b>NEXT</b> year, &quot;<code>1</code>&quot; is returned.</p>

<p>Otherwise the return value is identical with that of &quot;<code>Week_Number($year,$month,$day)</code>&quot;.</p>

<p><b>BEWARE</b> that using this function in scalar context is a <b>DANGEROUS</b> feature, because without knowing which year the week belongs to, you might inadvertently assume the wrong one!</p>

<p>If for instance you are iterating through an interval of dates, you might assume that the week always belongs to the same year as the given date, which unfortunately is <b>WRONG</b> in some cases!</p>

<p>In many years, the 31st of December for instance belongs to week number one of the <b>FOLLOWING</b> year. Assuming that the year is the same as your date (31st of December, in this example), sends you back to the first week of the <b>CURRENT</b> year - the Monday of which, by the way, in case of bad luck, might actually lie in the year <b>BEFORE</b> the current year!</p>

<p>This actually happens in 2002, for example.</p>

<p>So you always need to provide the correct corresponding year number by other means, keeping track of it yourself.</p>

<p>In case you do not understand this, never mind, but then simply <b>DO NOT USE</b> this function in scalar context!</p>

</li>
<li><p><code>($year,$month,$day) = Monday_of_Week($week,$year);</code></p>

<p>This function returns the date of the first day of the given week, i.e., the Monday.</p>

<p>&quot;<code>$year</code>&quot; must be greater than or equal to &quot;<code>1</code>&quot;, and &quot;<code>$week</code>&quot; must lie in the range &quot;<code>1</code>&quot; to &quot;<code>Weeks_in_Year($year)</code>&quot;.</p>

<p>Note that you can write &quot;<code>($year,$month,$day) = Monday_of_Week(Week_of_Year($year,$month,$day));</code>&quot; in order to calculate the date of the Monday of the same week as the given date.</p>

<p>If you want to calculate any other day of week in the same week as a given date, use</p>

<pre><code>  @date = Add_Delta_Days(Monday_of_Week(Week_of_Year(@date)),$offset);</code></pre>

<p>where <code>$offset = 1</code> for Tuesday, <code>2</code> for Wednesday etc.</p>

</li>
<li><p><code>if (($year,$month,$day) = Nth_Weekday_of_Month_Year($year,$month,$dow,$n))</code></p>

<p>This function calculates the date of the &quot;<code>$n</code>&quot;th day of week &quot;<code>$dow</code>&quot; in the given month &quot;<code>$month</code>&quot; and year &quot;<code>$year</code>&quot;; such as, for example, the 3rd Thursday of a given month and year.</p>

<p>This can be used to send a notification mail to the members of a group which meets regularly on every 3rd Thursday of a month, for instance.</p>

<p>(See the section &quot;RECIPES&quot; near the end of this document for a code snippet to actually do so.)</p>

<p>&quot;<code>$year</code>&quot; must be greater than or equal to &quot;<code>1</code>&quot;, &quot;<code>$month</code>&quot; must lie in the range &quot;<code>1</code>&quot; to &quot;<code>12</code>&quot;, &quot;<code>$dow</code>&quot; must lie in the range &quot;<code>1</code>&quot; to &quot;<code>7</code>&quot; and &quot;<code>$n</code>&quot; must lie in the range &quot;<code>1</code>&quot; to &quot;<code>5</code>&quot;, or a fatal error (with appropriate error message) occurs.</p>

<p>The function returns an empty list when the 5th of a given day of week does not exist in the given month and year.</p>

</li>
<li><p><code>($year,$week,$dow) = Standard_to_Business($year,$month,$day);</code></p>

<p>This function converts a given date from standard notation (year, month, day (of month)) to business notation (year, week, day of week).</p>

</li>
<li><p><code>($year,$month,$day) = Business_to_Standard($year,$week,$dow);</code></p>

<p>This function converts a given date from business notation (year, week, day of week) to standard notation (year, month, day (of month)).</p>

</li>
<li><p><code>$Dd = Delta_Days($year1,$month1,$day1, $year2,$month2,$day2);</code></p>

<p>This function returns the difference in days between the two given dates.</p>

<p>The result is positive if the two dates are in chronological order, i.e., if date #1 comes chronologically <b>BEFORE</b> date #2, and negative if the order of the two dates is reversed.</p>

<p>The result is zero if the two dates are identical.</p>

</li>
<li><p><code>($Dd,$Dh,$Dm,$Ds) = Delta_DHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2);</code></p>

<p>This function returns the difference in days, hours, minutes and seconds between the two given dates with times.</p>

<p>All four return values will be positive if the two dates are in chronological order, i.e., if date #1 comes chronologically <b>BEFORE</b> date #2, and negative (in all four return values!) if the order of the two dates is reversed.</p>

<p>This is so that the two functions &quot;<code>Delta_DHMS()</code>&quot; and &quot;<code>Add_Delta_DHMS()</code>&quot; (description see further below) are complementary, i.e., mutually inverse:</p>

<pre><code>  Add_Delta_DHMS(@date1,@time1, Delta_DHMS(@date1,@time1, @date2,@time2))</code></pre>

<p>yields &quot;<code>(@date2,@time2)</code>&quot; again, whereas</p>

<pre><code>  Add_Delta_DHMS(@date2,@time2,
      map(-$_, Delta_DHMS(@date1,@time1, @date2,@time2)))</code></pre>

<p>yields &quot;<code>(@date1,@time1)</code>&quot;, and</p>

<pre><code>  Delta_DHMS(@date1,@time1, Add_Delta_DHMS(@date1,@time1, @delta))</code></pre>

<p>yields &quot;<code>@delta</code>&quot; again.</p>

<p>The result is zero (in all four return values) if the two dates and times are identical.</p>

</li>
<li><p><code>($Dy,$Dm,$Dd) = Delta_YMD($year1,$month1,$day1, $year2,$month2,$day2);</code></p>

<p>This function returns the vector</p>

<pre><code>    ( $year2 - $year1, $month2 - $month1, $day2 - $day1 )</code></pre>

<p>This is called the &quot;one-by-one&quot; semantics.</p>

<p>Adding the result of this function to the first date always yields the second date again, and adding the negative result (where the signs of all elements of the result vector have been flipped) to the second date gives the first date. See also the description of the function &quot;Add_Delta_YMD()&quot; further below.</p>

<p>Example:</p>

<pre><code>  (6,2,-30) == Delta_YMD(1996,1,31, 2002,3,1]);

  [1996,1,31] + ( 6, 2,-30) = [2002,3, 1]
  [2002,3, 1] + (-6,-2, 30) = [1996,1,31]</code></pre>

<p>An error occurs if any of the two given dates is invalid.</p>

</li>
<li><p><code>($D_y,$D_m,$D_d, $Dh,$Dm,$Ds) = Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2);</code></p>

<p>This function is based on the function &quot;Delta_YMD()&quot; above but additionally calculates the time difference. When a carry over from the time difference occurs, the value of &quot;<code>$D_d</code>&quot; is adjusted accordingly, thus giving the correct total date/time difference.</p>

<p>Arguments are expected to be in chronological order to yield a (usually) positive result.</p>

<p>In any case, adding the result of this function to the first date/time value (<code>$year1,$month1,$day1,</code> <code>$hour1,$min1,$sec1</code>) always gives the second date/time value (<code>$year2,$month2,$day2,</code> <code>$hour2,$min2,$sec2</code>) again, and adding the negative result (with the signs of all elements of the result vector flipped) to the second date/time value gives the first date/time value.</p>

<p>See the function &quot;Add_Delta_YMDHMS()&quot; further below for adding a date/time value and a date/time difference.</p>

<p>An error occurs if any of the given two date/time values is invalid.</p>

</li>
<li><p><code>($Dy,$Dm,$Dd) = N_Delta_YMD($year1,$month1,$day1, $year2,$month2,$day2);</code></p>

<p>This function returns the difference between the two given dates in a more intuitive way (as far as possible - more on that see a bit further below) than the function &quot;Delta_YMD()&quot; described above.</p>

<p>The &quot;N&quot; which precedes its name is meant to signify &quot;new&quot; or &quot;normalized&quot;.</p>

<p>This function is loosely based on recipe #17 b) (see the section &quot;RECIPES&quot; below near the end of this document).</p>

<p>However, the code of recipe #17 b) actually does not treat positive and negative values symmetrically and consistently.</p>

<p>This new routine does.</p>

<p>The return values of this function are guaranteed to all have the same sign (or to be zero). This is why this function is called &quot;normalized&quot;.</p>

<p>Moreover, the results are guaranteed to be &quot;minimal&quot;, in the sense that <code>|$Dm| &lt; 12</code> and <code>|$Dd| &lt; 31</code> (which is equivalent to <code>$Dm</code> lying in the range <code>[-11..+11]</code> and <code>$Dd</code> lying in the range <code>[-30..+30]</code>).</p>

<p>When the results are applied (i.e., added) to the first given date in a left-to-right order, the second given date is guaranteed to be obtained, provided that intermediary results are truncated, as done by the function &quot;Add_Delta_YM()&quot; (see further below), i.e., that invalid intermediate dates such as e.g. [2009,2,31] will automatically be transformed into [2009,2,28] (and not &quot;wrapped&quot; into the next month, e.g. to [2009,3,3]).</p>

<p>This is called the &quot;left-to-right with truncation&quot; semantics.</p>

<p>Note that reversing the order of the given dates and reversing the sign of each of the result values will not always add up.</p>

<p>Consider the dates [2008,2,29] and [2009,2,1]: their difference is (0,11,3) ([2008,2,29] plus 11 months is [2009,1,29], which plus 3 days is [2009,2,1]), but the difference between [2009,2,1] and [2008,2,29] is (0,-11,-1), and not (0,-11,-3) ([2009,2,1] minus 11 months is [2008,3,1], which minus one day is [2008,2,29]).</p>

<p>Another example: The difference between [1996,2,29] and [1997,2,28] is (1,0,0) (observe the truncation of the invalid date [1997,2,29] to [1997,2,28] here!), whereas the difference between [1997,2,28] and [1996,2,29] is (0,-11,-28) ([1997,2,28] minus 11 months is [1996,3,28], which minus 28 days is not [1996,3,0] but of course [1996,2,29]).</p>

<p>&quot;Benign&quot; examples such as for instance the difference between [1964,1,3] and [2009,9,10] are completely symmetrical: The difference in this example is (45,8,7), whereas the difference between [2009,9,10] and [1964,1,3] is (-45,-8,-7), as would normally be expected. In this example, the result is also the same as the one returned by &quot;Delta_YMD()&quot;.</p>

<p>All these counter-intuitive effects are due to the fact that months (and due to leap years, also years) do not correspond to a fixed number of days, so the semantics of &quot;plus one month&quot; or &quot;plus one year&quot; are in fact undefined.</p>

<p>The present function is an attempt to provide a definition which is intuitive most of the time, and at least consistent the rest of the time.</p>

<p>Other definitions are of course possible, but most often lead to contradictions (e.g., the results and the given first date do not add up to the second given date).</p>

<p>See the file &quot;datecalc.pl&quot; in the &quot;examples&quot; subdirectory of this distribution for a way to play around with this function, or go to http://www.engelschall.com/u/sb/datecalc/ for the online version.</p>

<p>An error occurs if any of the two given dates is invalid, or if any intermediate result leads to an invalid date (this does not apply to truncation, however, as explained above).</p>

</li>
<li><p><code>($D_y,$D_m,$D_d, $Dhh,$Dmm,$Dss) = N_Delta_YMDHMS($year1,$month1,$day1, $hour1,$min1,$sec1, $year2,$month2,$day2, $hour2,$min2,$sec2);</code></p>

<p>This function essentially does the same as the function &quot;N_Delta_YMD()&quot; described immediately above, except that also the difference in hours, minutes and seconds is taken into account.</p>

<p>This function is loosely based on recipe #17 a) (see the section &quot;RECIPES&quot; below near the end of this document).</p>

<p>However, the code of recipe #17 a) actually does not treat positive and negative values symmetrically and consistently.</p>

<p>This new routine does.</p>

<p>The return values of this function (including the time differences) are guaranteed to all have the same sign (or to be zero). This is the reason for the &quot;N&quot; that precedes the name of this function, which is intended to mean &quot;normalized&quot; (or &quot;new&quot;).</p>

<p>Moreover, the results are guaranteed to be &quot;minimal&quot;, in the sense that <code>|$D_m| &lt; 12</code>, <code>|$D_d| &lt; 31</code>, <code>|$Dhh| &lt; 24</code>, <code>|$Dmm| &lt; 60</code> and <code>|$Dss| &lt; 60</code> (which is equivalent to <code>$D_m</code> lying in the range <code>[-11..+11]</code>, <code>$D_d</code> lying in the range <code>[-30..+30]</code>, <code>$Dhh</code> lying in the range <code>[-23..+23]</code>, and <code>$Dmm</code> and <code>$Dss</code> both lying in the range <code>[-59..+59]</code>).</p>

</li>
<li><p><code>($Dd,$Dh,$Dm,$Ds) = Normalize_DHMS($Dd,$Dh,$Dm,$Ds);</code></p>

<p>This function takes four arbitrary values for days, hours, minutes and seconds (which may have different signs) and renormalizes them so that the values for hours, minutes and seconds will lie in the ranges <code>[-23..23]</code>, <code>[-59..59]</code> and <code>[-59..59]</code>, respectively, and so that all four values have the same sign (or are zero).</p>

<p>The given values are left untouched, i.e., unchanged.</p>

</li>
<li><p><code>($year,$month,$day) = Add_Delta_Days($year,$month,$day, $Dd);</code></p>

<p>This function has two principal uses:</p>

<p>First, it can be used to calculate a new date, given an initial date and an offset (which may be positive or negative) in days, in order to answer questions like &quot;today plus 90 days -- which date gives that?&quot;.</p>

<p>(In order to add a weeks offset, simply multiply the weeks offset with &quot;<code>7</code>&quot; and use that as your days offset.)</p>

<p>Second, it can be used to convert the canonical representation of a date, i.e., the number of that day (where counting starts at the 1st of January in <span style="white-space: nowrap;">1 A.D.</span>), back into a date given as year, month and day.</p>

<p>Because counting starts at &quot;<code>1</code>&quot;, you will actually have to subtract &quot;<code>1</code>&quot; from the canonical date in order to get back the original date:</p>

<pre><code>  $canonical = Date_to_Days($year,$month,$day);

  ($year,$month,$day) = Add_Delta_Days(1,1,1, $canonical - 1);</code></pre>

<p>Moreover, this function is the inverse of the function &quot;<code>Delta_Days()</code>&quot;:</p>

<pre><code>  Add_Delta_Days(@date1, Delta_Days(@date1, @date2))</code></pre>

<p>yields &quot;<code>@date2</code>&quot; again, whereas</p>

<pre><code>  Add_Delta_Days(@date2, -Delta_Days(@date1, @date2))</code></pre>

<p>yields &quot;<code>@date1</code>&quot;, and</p>

<pre><code>  Delta_Days(@date1, Add_Delta_Days(@date1, $delta))</code></pre>

<p>yields &quot;<code>$delta</code>&quot; again.</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS($year,$month,$day, $hour,$min,$sec, $Dd,$Dh,$Dm,$Ds);</code></p>

<p>This function serves to add a days, hours, minutes and seconds offset to a given date and time, in order to answer questions like &quot;today and now plus 7 days but minus 5 hours and then plus 30 minutes, what date and time gives that?&quot;:</p>

<pre><code>  ($y,$m,$d,$H,$M,$S) = Add_Delta_DHMS(Today_and_Now(), +7,-5,+30,0);</code></pre>

</li>
<li><p><code>($year,$month,$day) = Add_Delta_YM($year,$month,$day, $Dy,$Dm);</code></p>

<p>This function can be used to add a year and/or month offset to a given date.</p>

<p>In contrast to the function described immediately below (&quot;<code>Add_Delta_YMD()</code>&quot;), this function does no &quot;wrapping&quot; into the next month if the day happens to lie outside the valid range for the resulting year and month (after adding the year and month offsets). Instead, it simply truncates the day to the last possible day of the resulting month.</p>

<p>Examples:</p>

<p>Adding an offset of 0 years, 1 month to the date [1999,1,31] would result in the (invalid) date [1999,2,31]. The function replaces this result by the (valid) date [1999,2,28].</p>

<p>Adding an offset of 1 year, 1 month to the same date [1999,1,31] as above would result in the (still invalid) date [2000,2,31]. The function replaces this result by the valid date [2000,2,29] (because 2000 is a leap year).</p>

<p>Note that the year and month offsets can be negative, and that they can have different signs.</p>

<p>If you want to additionally add a days offset, use the function &quot;<code>Add_Delta_Days()</code>&quot; before or after calling &quot;<code>Add_Delta_YM()</code>&quot;:</p>

<pre><code>  @date2 = Add_Delta_Days( Add_Delta_YM(@date1, $Dy,$Dm), $Dd );
  @date2 = Add_Delta_YM( Add_Delta_Days(@date1, $Dd), $Dy,$Dm );</code></pre>

<p>Note that your result may depend on the order in which you call these two functions!</p>

<p>Consider the date [1999,2,28] and the offsets 0 years, 1 month and 1 day:</p>

<p>[1999,2,28] plus one month is [1999,3,28], plus one day is [1999,3,29]. [1999,2,28] plus one day is [1999,3,1], plus one month is [1999,4,1].</p>

<p>(Which is also the reason why the &quot;<code>Add_Delta_YM()</code>&quot; function does not allow to add a days offset, because this would actually require TWO functions: One for adding the days offset BEFORE and one for adding it AFTER applying the year/month offsets.)</p>

<p>An error occurs if the initial date is not valid.</p>

<p>Note that &quot;<code>Add_Delta_YM( Add_Delta_YM(@date, $Dy,$Dm), -$Dy,-$Dm );</code>&quot; will not, in general, return the original date &quot;<code>@date</code>&quot; (consider the examples given above!).</p>

</li>
<li><p><code>($year,$month,$day) = Add_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd);</code></p>

<p>This function serves to add a years, months and days offset to a given date.</p>

<p>(In order to add a weeks offset, simply multiply the weeks offset with &quot;<code>7</code>&quot; and add this number to your days offset.)</p>

<p>Note that the three offsets for years, months and days are applied independently from each other. This also allows them to have different signs.</p>

<p>The years and months offsets are applied first, and the days offset is applied last.</p>

<p>If the resulting date happens to fall on a day after the end of the resulting month, like the 32nd of April or the 30th of February, then the date is simply counted forward into the next month (possibly also into the next year) by the number of excessive days (e.g., the 32nd of April will become the 2nd of May).</p>

<p><b>BEWARE</b> that this behaviour differs from that of previous versions of this module! In previous versions, the day was simply truncated to the maximum number of days in the resulting month.</p>

<p>If you want the previous behaviour, use the new function &quot;<code>Add_Delta_YM()</code>&quot; (described immediately above) plus the function &quot;<code>Add_Delta_Days()</code>&quot; instead.</p>

<p><b>BEWARE</b> also that because a year and a month offset is not equivalent to a fixed number of days, the transformation performed by this function is <b>NOT ALWAYS REVERSIBLE</b>!</p>

<p>This is in contrast to the functions &quot;<code>Add_Delta_Days()</code>&quot; and &quot;<code>Add_Delta_DHMS()</code>&quot;, which are fully and truly reversible (with the help of the functions &quot;<code>Delta_Days()</code>&quot; and &quot;<code>Delta_DHMS()</code>&quot;, for instance).</p>

<p>Note that for this same reason,</p>

<pre><code>  @date = Add_Delta_YMD(
          Add_Delta_YMD(@date, $Dy,$Dm,$Dd), -$Dy,-$Dm,-$Dd);</code></pre>

<p>will in general <b>NOT</b> return the initial date &quot;<code>@date</code>&quot;, even though</p>

<pre><code>  @date2 = Add_Delta_YMD( @date1, Delta_YMD(@date1, @date2) );</code></pre>

<p>will always return the second date &quot;<code>@date2</code>&quot;, and</p>

<pre><code>  @date1 = Add_Delta_YMD( @date2, map(-$_, Delta_YMD(@date1, @date2)) );</code></pre>

<p>which is the same as</p>

<pre><code>  @date1 = Add_Delta_YMD( @date2, Delta_YMD(@date2, @date1) );</code></pre>

<p>will always return the first date &quot;<code>@date1</code>&quot;.</p>

<p>Examples:</p>

<pre><code>  [1996,1,31] + ( 6, 1,-2) = [2002,3,1]
  [2002,3, 1] + (-6,-1, 2) = [1996,2,3] # EXPECTED: [1996,1,31]

  (6,2,-30) == Delta_YMD(1996,1,31, 2002,3,1);

  [1996,1,31] + ( 6, 2,-30) = [2002,3, 1]
  [2002,3, 1] + (-6,-2, 30) = [1996,1,31] # OK

  (6,1,-2) == Delta_YMD(1996,2,3, 2002,3,1);

  [1996,2,3] + ( 6, 1,-2) = [2002,3,1]
  [2002,3,1] + (-6,-1, 2) = [1996,2,3] # OK</code></pre>

<p>Note that this is <b>NOT</b> a program bug but <b>NECESSARILY</b> so, because of the variable lengths of years and months, and hence because of the ambiguity of the difference between two dates in terms of years, months and days, i.e., the fact that the difference between two dates can be expressed in more than one way:</p>

<pre><code>  [1996,1,31] + (6,1, -2) = [2002,3,1]
  [1996,1,31] + (6,2,-30) = [2002,3,1]</code></pre>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec) = Add_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec, $D_y,$D_m,$D_d, $Dh,$Dm,$Ds);</code></p>

<p>Same as the function above, except that a time offset may be given in addition to the year, month and day offset.</p>

</li>
<li><p><code>($year,$month,$day) = Add_N_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd);</code></p>

<p>This function is actually a shortcut for applying the function &quot;Add_Delta_YM()&quot; first, followed by the function &quot;Add_Delta_Days()&quot;, i.e., this function does exactly the same as</p>

<pre><code> ($year,$month,$day) = Add_Delta_Days( Add_Delta_YM($year,$month,$day,$Dy,$Dm), $Dd );</code></pre>

<p>Beware that, if necessary, the function &quot;Add_Delta_YM()&quot; truncates the resulting day of the month to the largest allowable value for that month, i.e., the (invalid) result [2009,2,31] is automatically transformed into [2009,2,28].</p>

<p>For more details on this truncation, see the description of the function &quot;Add_Delta_YM()&quot; further above.</p>

<p>This function is meant to be complementary with the function &quot;N_Delta_YMD()&quot; described further above.</p>

<p>This means that it is guaranteed that the result returned by</p>

<pre><code>  Add_N_Delta_YMD( @date1, N_Delta_YMD(@date1, @date2) );</code></pre>

<p>is always identical with the given date &quot;<code>@date2</code>&quot;.</p>

<p>Note however that unlike with function &quot;Add_Delta_YMD()&quot;, the reverse is not true here, i.e.,</p>

<pre><code>  ($Dy,$Dm,$Dd) = N_Delta_YMD(@date1,@date2);
  @date = Add_N_Delta_YMD(@date2, -$Dy,-$Dm,-$Dd);</code></pre>

<p>will <b>NOT</b> always return the initial date &quot;<code>@date1</code>&quot;.</p>

<p>Example:</p>

<pre><code>  (0,11,3) == N_Delta_YMD(2008,2,29, 2009,2,1);

  [2008,2,29] + (0, 11, 3) = [2009,2, 1]
  [2009,2, 1] + (0,-11,-3) = [2008,2,27] # EXPECTED: [2008,2,29]</code></pre>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec) = Add_N_Delta_YMDHMS($year,$month,$day, $hour,$min,$sec, $D_y,$D_m,$D_d, $Dhh,$Dmm,$Dss);</code></p>

<p>This function essentially does the same as the function &quot;Add_N_Delta_YMD()&quot; described immediately above, except that also the difference in hours, minutes and seconds is taken into account.</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = System_Clock([$gmt]);</code></p>

<p>If your operating system supports the corresponding system calls (&quot;<code>time()</code>&quot; and &quot;<code>localtime()</code>&quot; or &quot;<code>gmtime()</code>&quot;), this function will return the information provided by your system clock, i.e., the current date and time, the number of the day of year, the number of the day of week and a flag signaling whether daylight savings time is currently in effect or not.</p>

<p>The ranges of values returned (and their meanings) are as follows:</p>

<pre><code>        $year   :   1970..2038 (or more)  [Unix etc.]
        $year   :   1904..2040            [MacOS Classic]

        $month  :   1..12
        $day    :   1..31
        $hour   :   0..23
        $min    :   0..59
        $sec    :   0..59    (0..61 on some systems)
        $doy    :   1..366
        $dow    :   1..7
        $dst    :  -1..1</code></pre>

<p>&quot;<code>$doy</code>&quot; is the day of year, sometimes also referred to as the &quot;julian date&quot;, which starts at &quot;<code>1</code>&quot; and goes up to the number of days in that year.</p>

<p>The day of week (&quot;<code>$dow</code>&quot;) will be &quot;<code>1</code>&quot; for Monday, &quot;<code>2</code>&quot; for Tuesday and so on until &quot;<code>7</code>&quot; for Sunday.</p>

<p>The daylight savings time flag (&quot;<code>$dst</code>&quot;) will be &quot;<code>-1</code>&quot; if this information is not available on your system, &quot;<code>0</code>&quot; for no daylight savings time (i.e., winter time) and &quot;<code>1</code>&quot; when daylight savings time is in effect.</p>

<p>If your operating system does not provide the necessary system calls, calling this function will result in a fatal &quot;not available on this system&quot; error message.</p>

<p>If you want to handle this exception yourself, use &quot;<code>eval</code>&quot; as follows:</p>

<pre><code>  eval { ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) =
    System_Clock(); };

  if ($@)
  {
      # Handle missing system clock
      # (For instance, ask user to enter this information manually)
  }</code></pre>

<p>Note that curlies (&quot;{&quot; and &quot;}&quot;) are used here to delimit the statement to be &quot;eval&quot;ed (which is the way to catch exceptions in Perl), and not quotes (which is a way to evaluate Perl expressions at runtime).</p>

<p>If the optional (boolean) input parameter &quot;<code>$gmt</code>&quot; is given, a &quot;true&quot; value (&quot;<code>1</code>&quot;) will cause &quot;<code>gmtime()</code>&quot; to be used instead of &quot;<code>localtime()</code>&quot;, internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time.</p>

</li>
<li><p><code>($year,$month,$day) = Today([$gmt]);</code></p>

<p>This function returns a subset of the values returned by the function &quot;<code>System_Clock()</code>&quot; (see above for details), namely the current year, month and day.</p>

<p>A fatal &quot;not available on this system&quot; error message will appear if the corresponding system calls are not supported by your current operating system.</p>

<p>If the optional (boolean) input parameter &quot;<code>$gmt</code>&quot; is given, a &quot;true&quot; value (&quot;<code>1</code>&quot;) will cause &quot;<code>gmtime()</code>&quot; to be used instead of &quot;<code>localtime()</code>&quot;, internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time.</p>

</li>
<li><p><code>($hour,$min,$sec) = Now([$gmt]);</code></p>

<p>This function returns a subset of the values returned by the function &quot;<code>System_Clock()</code>&quot; (see above for details), namely the current time (hours, minutes and full seconds).</p>

<p>A fatal &quot;not available on this system&quot; error message will appear if the corresponding system calls are not supported by your current operating system.</p>

<p>If the optional (boolean) input parameter &quot;<code>$gmt</code>&quot; is given, a &quot;true&quot; value (&quot;<code>1</code>&quot;) will cause &quot;<code>gmtime()</code>&quot; to be used instead of &quot;<code>localtime()</code>&quot;, internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time.</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]);</code></p>

<p>This function returns a subset of the values returned by the function &quot;<code>System_Clock()</code>&quot; (see above for details), namely the current date (year, month, day) and time (hours, minutes and full seconds).</p>

<p>A fatal &quot;not available on this system&quot; error message will appear if the corresponding system calls are not supported by your current operating system.</p>

<p>If the optional (boolean) input parameter &quot;<code>$gmt</code>&quot; is given, a &quot;true&quot; value (&quot;<code>1</code>&quot;) will cause &quot;<code>gmtime()</code>&quot; to be used instead of &quot;<code>localtime()</code>&quot;, internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time.</p>

</li>
<li><p><code>$year = This_Year([$gmt]);</code></p>

<p>This function returns the current year, according to local time.</p>

<p>A fatal &quot;not available on this system&quot; error message will appear if the corresponding system calls are not supported by your current operating system.</p>

<p>If the optional (boolean) input parameter &quot;<code>$gmt</code>&quot; is given, a &quot;true&quot; value (&quot;<code>1</code>&quot;) will cause &quot;<code>gmtime()</code>&quot; to be used instead of &quot;<code>localtime()</code>&quot;, internally, thus returning Greenwich Mean Time (GMT, or UTC) instead of local time. However, this will only make a difference within a few hours around New Year (unless you are on a Pacific island, where this can be almost 24 hours).</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Gmtime([time]);</code></p>

<p>This is Date::Pcalc&#39;s equivalent of Perl&#39;s built-in &quot;gmtime()&quot; function. See also <a href="http://man.he.net/man1/perlfunc">&quot;gmtime&quot; in perlfunc(1)</a>.</p>

<p>With the optional argument &quot;time&quot; (i.e., seconds since the epoch), this function will return the corresponding values for that particular time (instead of the current time when this parameter is omitted).</p>

<p>The ranges of values returned (and their meanings) are as follows:</p>

<pre><code>        $year   :   1970..2038 (or more)  [Unix etc.]
        $year   :   1904..2040            [MacOS Classic]

        $month  :   1..12
        $day    :   1..31
        $hour   :   0..23
        $min    :   0..59
        $sec    :   0..59
        $doy    :   1..366
        $dow    :   1..7
        $dst    :  -1..1</code></pre>

<p>&quot;<code>$doy</code>&quot; is the day of year, sometimes also referred to as the &quot;julian date&quot;, which starts at &quot;<code>1</code>&quot; and goes up to the number of days in that year.</p>

<p>The day of week (&quot;<code>$dow</code>&quot;) will be &quot;<code>1</code>&quot; for Monday, &quot;<code>2</code>&quot; for Tuesday and so on until &quot;<code>7</code>&quot; for Sunday.</p>

<p>The daylight savings time flag (&quot;<code>$dst</code>&quot;) will be &quot;<code>-1</code>&quot; if this information is not available on your system, &quot;<code>0</code>&quot; for no daylight savings time (i.e., winter time) and &quot;<code>1</code>&quot; when daylight savings time is in effect.</p>

<p>A fatal &quot;time out of range&quot; error will occur if the given time value is out of range <code>[0..(~0&gt;&gt;1)]</code>.</p>

<p>If the time value is omitted, the &quot;time()&quot; function is called instead, internally.</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Localtime([time]);</code></p>

<p>This is Date::Pcalc&#39;s equivalent of Perl&#39;s built-in &quot;localtime()&quot; function. See also <a href="http://man.he.net/man1/perlfunc">&quot;localtime&quot; in perlfunc(1)</a>.</p>

<p>The ranges of values returned (and their meanings) are as follows:</p>

<pre><code>        $year   :   1970..2038 (or more)  [Unix etc.]
        $year   :   1904..2040            [MacOS Classic]

        $month  :   1..12
        $day    :   1..31
        $hour   :   0..23
        $min    :   0..59
        $sec    :   0..59
        $doy    :   1..366
        $dow    :   1..7
        $dst    :  -1..1</code></pre>

<p>&quot;<code>$doy</code>&quot; is the day of year, sometimes also referred to as the &quot;julian date&quot;, which starts at &quot;<code>1</code>&quot; and goes up to the number of days in that year.</p>

<p>The day of week (&quot;<code>$dow</code>&quot;) will be &quot;<code>1</code>&quot; for Monday, &quot;<code>2</code>&quot; for Tuesday and so on until &quot;<code>7</code>&quot; for Sunday.</p>

<p>The daylight savings time flag (&quot;<code>$dst</code>&quot;) will be &quot;<code>-1</code>&quot; if this information is not available on your system, &quot;<code>0</code>&quot; for no daylight savings time (i.e., winter time) and &quot;<code>1</code>&quot; when daylight savings time is in effect.</p>

<p>A fatal &quot;time out of range&quot; error will occur if the given time value is out of range <code>[0..(~0&gt;&gt;1)]</code>.</p>

<p>If the time value is omitted, the &quot;time()&quot; function is called instead, internally.</p>

</li>
<li><p><code>$time = Mktime($year,$month,$day, $hour,$min,$sec);</code></p>

<p>This function converts a date into a time value, i.e., into the number of seconds since whatever moment in time your system considers to be the &quot;epoch&quot;. On Unix and most other systems this is the number of seconds since January 1st 1970 at midnight (GMT). On MacOS Classic this is the number of seconds since January 1st 1904 at midnight (local time).</p>

<p>The function is similar to the &quot;POSIX::mktime()&quot; function (see <a href="http://man.he.net/man1/POSIX">&quot;mktime&quot; in POSIX(1)</a> for more details), but in contrast to the latter, it expects dates in the usual ranges used throughout this module: The year 2001 stays year 2001, and months are numbered from 1 to 12.</p>

<p>A fatal &quot;date out of range&quot; error will occur if the given date cannot be expressed in terms of seconds since the epoch (this happens for instance when the date lies before the epoch, or if it is later than <span style="white-space: nowrap;">19-Jan-2038 03:14:07 GMT</span> on <span style="white-space: nowrap;">32 bit</span> Unix systems, or later than <span style="white-space: nowrap;">06-Feb-2040 06:28:15</span> (local time) on a Macintosh with MacOS Classic).</p>

<p>Just like the &quot;POSIX::mktime()&quot; function, this function uses the &quot;mktime()&quot; system call, internally.</p>

<p>This means that the given date and time is considered to be in local time, and that the value returned by this function will depend on your machine&#39;s local settings such as the time zone, whether daylight savings time is (or was, at the time) in effect, and the system clock itself.</p>

<p><b>BEWARE</b> that &quot;mktime()&quot; does not always return the same time value as fed into &quot;localtime()&quot;, when you feed the output of &quot;localtime()&quot; back into &quot;mktime()&quot;, on some systems!</p>

<p>I.e., &quot;<code>Mktime((Localtime($time))[0..5])</code>&quot; will not always return the same value as given in &quot;<code>$time</code>&quot;!</p>

<p>Note that since Perl does not provide any access to the internal system call &quot;mktime()&quot;, in this pure Perl version, &quot;Mktime()&quot; is calculated as follows:</p>

<pre><code>  Date_to_Time(Add_Delta_YMDHMS(@_,map(-$_,(Timezone(Date_to_Time(@_)))[0..5])));</code></pre>

<p>This may or may not yield the same result as &quot;mktime()&quot;.</p>

<p>No guarantees whatsoever are given here for that! Use at your own risk!</p>

</li>
<li><p><code>($D_y,$D_m,$D_d, $Dh,$Dm,$Ds, $dst) = Timezone([time]);</code></p>

<p>This function returns the difference between &quot;<code>localtime(time)</code>&quot; and &quot;<code>gmtime(time)</code>&quot;, which is the timezone offset in effect for the current location and the given &quot;<code>time</code>&quot;.</p>

<p>This offset is positive if you are located to the east of Greenwich, and is usually negative (except during daylight savings time, in some locations) if you are located to the west of Greenwich.</p>

<p>Note that this offset is influenced by all of the relevant system settings and parameters on your machine; such as locales, environment variables (e.g. &quot;<code>TZ</code>&quot;) and the system clock itself. See the relevant documentation on your system for more details.</p>

<p>If the &quot;<code>time</code>&quot; is omitted, the &quot;<code>time()</code>&quot; function will be called automatically, internally (similar to the built-in functions &quot;<code>localtime()</code>&quot; and &quot;<code>gmtime()</code>&quot; in Perl).</p>

<p>A fatal &quot;time out of range&quot; error will occur if the given time value is out of range <code>[0..(~0&gt;&gt;1)]</code>.</p>

<p>The last item of the returned list is a flag which indicates whether daylight savings time is currently in effect. This flag is negative (-1) if this information is not available on your system. It is zero (0) when daylight savings time is off, and positive (+1) when daylight savings time is on.</p>

<p>Thus you can check very quickly whether daylight savings time is currently in effect by evaluating this function in scalar context (in scalar context, Perl returns the last item of a list):</p>

<pre><code>  if (scalar Timezone &gt; 0) { # yes, daylight savings time</code></pre>

<p>However, a slightly more efficient way would be this:</p>

<pre><code>  if (scalar System_Clock &gt; 0) { # yes, daylight savings time</code></pre>

</li>
<li><p><code>$time = Date_to_Time($year,$month,$day, $hour,$min,$sec);</code></p>

<p>This function is a replacement for the BSD function &quot;timegm()&quot; (which is not available on all Unix systems), which converts a given date and time into a time value, i.e., into the number of seconds since whatever moment in time your system considers to be the &quot;epoch&quot;. On Unix and most other systems this is the number of seconds since January 1st 1970 at midnight (GMT). On MacOS Classic this is the number of seconds since January 1st 1904 at midnight (local time).</p>

<p>Under Unix, the date and time are considered to be in UTC (&quot;Universal Time Coordinated&quot;, and so is the resulting time value.</p>

<p>UTC is almost the same as GMT (or &quot;Greenwich Mean Time&quot;), except that UTC has leap seconds (in order to account for small variations in the rotation of the earth, for instance), whereas GMT does not.</p>

<p>Under MacOS Classic, however, both input and output are considered to be in local time.</p>

<p>The ranges of year and month follow the same rules as throughout the rest of this module (and not the contorted rules of its Unix equivalent), i.e., the year &quot;2001&quot; stays &quot;2001&quot; and the month ranges from 1 to 12.</p>

<p>A fatal &quot;date out of range&quot; error will occur if the given date cannot be expressed in terms of seconds since the epoch (this happens for instance when the date lies before the epoch, or if it is later than <span style="white-space: nowrap;">19-Jan-2038 03:14:07 GMT</span> on <span style="white-space: nowrap;">32 bit</span> Unix systems, or later than <span style="white-space: nowrap;">06-Feb-2040 06:28:15</span> (local time) on a Macintosh with MacOS Classic).</p>

<p>This function should be very fast, because it is implemented in a very straightforward manner and doesn&#39;t use any internal system calls.</p>

<p>Moreover, the functions &quot;Date_to_Time()&quot; and &quot;Time_to_Date()&quot; are guaranteed to be complementary, i.e., that &quot;<code>Date_to_Time(Time_to_Date($time))</code>&quot; and &quot;<code>Time_to_Date(Date_to_Time($year,$month,$day, $hour,$min,$sec))</code>&quot; will always return the initial values.</p>

</li>
<li><p><code>($year,$month,$day, $hour,$min,$sec) = Time_to_Date([time]);</code></p>

<p>This function is an alternative to the POSIX &quot;gmtime()&quot; function (and its built-in Perl equivalent), which converts a given time value into the corresponding date and time. The given time value must be the number of seconds since whatever moment in time your system considers to be the &quot;epoch&quot;. On Unix and most other systems this is the number of seconds since January 1st 1970 at midnight (GMT). On MacOS Classic this is the number of seconds since January 1st 1904 at midnight (local time).</p>

<p>Under Unix, the given time value is considered to be in UTC (&quot;Universal Time Coordinated&quot;, and so is the resulting date and time.</p>

<p>UTC is almost the same as GMT (or &quot;Greenwich Mean Time&quot;), except that UTC has leap seconds (in order to account for small variations in the rotation of the earth, for instance), whereas GMT does not.</p>

<p>Under MacOS Classic, however, both input and output are considered to be in local time.</p>

<p>If the input value &quot;<code>time</code>&quot; is omitted, the &quot;<code>time()</code>&quot; function will be called automatically, internally (similar to the built-in functions &quot;<code>localtime()</code>&quot; and &quot;<code>gmtime()</code>&quot; in Perl).</p>

<p>A fatal &quot;time out of range&quot; error will occur if the given time value is negative.</p>

<p>This function should be very fast, because it is implemented in a very straightforward manner and doesn&#39;t use any internal system calls (except for &quot;time()&quot;, if the input value is omitted).</p>

<p>Moreover, the functions &quot;Date_to_Time()&quot; and &quot;Time_to_Date()&quot; are guaranteed to be complementary, i.e., that &quot;<code>Date_to_Time(Time_to_Date($time))</code>&quot; and &quot;<code>Time_to_Date(Date_to_Time($year,$month,$day, $hour,$min,$sec))</code>&quot; will always return the initial values.</p>

</li>
<li><p><code>($year,$month,$day) = Easter_Sunday($year);</code></p>

<p>This function calculates the date of Easter Sunday for all years in the range from 1583 to 2299 (all other year numbers will result in a fatal &quot;year out of range&quot; error message) using the method known as the &quot;Gaussian Rule&quot;.</p>

<p>Some related christian feast days which depend on the date of Easter Sunday:</p>

<pre><code>  Carnival Monday / Rosenmontag / Veille du Mardi Gras   =  -48 days
  Mardi Gras / Karnevalsdienstag / Mardi Gras            =  -47 days
  Ash Wednesday / Aschermittwoch / Mercredi des Cendres  =  -46 days
  Palm Sunday / Palmsonntag / Dimanche des Rameaux       =   -7 days
  Easter Friday / Karfreitag / Vendredi Saint            =   -2 days
  Easter Saturday / Ostersamstag / Samedi de Paques      =   -1 day
  Easter Monday / Ostermontag / Lundi de Paques          =   +1 day
  Ascension of Christ / Christi Himmelfahrt / Ascension  =  +39 days
  Whitsunday / Pfingstsonntag / Dimanche de Pentecote    =  +49 days
  Whitmonday / Pfingstmontag / Lundi de Pentecote        =  +50 days
  Feast of Corpus Christi / Fronleichnam / Fete-Dieu     =  +60 days</code></pre>

<p>Use the offsets shown above to calculate the date of the corresponding feast day as follows:</p>

<pre><code>  ($year,$month,$day) = Add_Delta_Days(Easter_Sunday($year), $offset));</code></pre>

</li>
<li><p><code>if ($month = Decode_Month($string[,$lang]))</code></p>

<p>This function takes a string as its argument, which should contain the name of a month in the given or currently selected language (see further below for details about the multi-language support of this package), or any uniquely identifying abbreviation of a month&#39;s name (i.e., the first few letters), and returns the corresponding number (1..12) upon a successful match, or &quot;<code>0</code>&quot; otherwise (therefore, the return value can also be used as the conditional expression in an &quot;if&quot; statement).</p>

<p>Note that the input string may not contain any other characters which do not pertain to the month&#39;s name, especially no leading or trailing whitespace.</p>

<p>Note also that matching is performed in a case-insensitive manner (this may depend on the &quot;locale&quot; setting on your current system, though!)</p>

<p>With &quot;1&quot; (&quot;English&quot;) as the given language, the following examples will all return the value &quot;<code>9</code>&quot;:</p>

<pre><code>  $month = Decode_Month(&quot;s&quot;,1);
  $month = Decode_Month(&quot;Sep&quot;,1);
  $month = Decode_Month(&quot;septemb&quot;,1);
  $month = Decode_Month(&quot;September&quot;,1);</code></pre>

</li>
<li><p><code>if ($dow = Decode_Day_of_Week($string[,$lang]))</code></p>

<p>This function takes a string as its argument, which should contain the name of a day of week in the given or currently selected language (see further below for details about the multi-language support of this package), or any uniquely identifying abbreviation of the name of a day of week (i.e., the first few letters), and returns the corresponding number (1..7) upon a successful match, or &quot;<code>0</code>&quot; otherwise (therefore, the return value can also be used as the conditional expression in an &quot;if&quot; statement).</p>

<p>Note that the input string may not contain any other characters which do not pertain to the name of the day of week, especially no leading or trailing whitespace.</p>

<p>Note also that matching is performed in a case-insensitive manner (this may depend on the &quot;locale&quot; setting on your current system, though!)</p>

<p>With &quot;1&quot; (&quot;English&quot;) as the given language, the following examples will all return the value &quot;<code>3</code>&quot;:</p>

<pre><code>  $dow = Decode_Day_of_Week(&quot;w&quot;,1);
  $dow = Decode_Day_of_Week(&quot;Wed&quot;,1);
  $dow = Decode_Day_of_Week(&quot;wednes&quot;,1);
  $dow = Decode_Day_of_Week(&quot;Wednesday&quot;,1);</code></pre>

</li>
<li><p><code>if ($lang = Decode_Language($string))</code></p>

<p>This function takes a string as its argument, which should contain the name of one of the languages supported by this package (<b>IN THIS VERY LANGUAGE ITSELF</b>), or any uniquely identifying abbreviation of the name of a language (i.e., the first few letters), and returns its corresponding internal number (1..14 in the original distribution) upon a successful match, or &quot;<code>0</code>&quot; otherwise (therefore, the return value can also be used as the conditional expression in an &quot;if&quot; statement).</p>

<p>Note that the input string may not contain any other characters which do not pertain to the name of a language, especially no leading or trailing whitespace.</p>

<p>Note also that matching is performed in a case-insensitive manner (this may depend on the &quot;locale&quot; setting on your current system, though!)</p>

<p>The original distribution supports the following fourteen languages:</p>

<pre><code>            English                    ==&gt;    1    (default)
            Fran&ccedil;ais    (French)       ==&gt;    2
            Deutsch     (German)       ==&gt;    3
            Espa&ntilde;ol     (Spanish)      ==&gt;    4
            Portugu&ecirc;s   (Portuguese)   ==&gt;    5
            Nederlands  (Dutch)        ==&gt;    6
            Italiano    (Italian)      ==&gt;    7
            Norsk       (Norwegian)    ==&gt;    8
            Svenska     (Swedish)      ==&gt;    9
            Dansk       (Danish)       ==&gt;   10
            suomi       (Finnish)      ==&gt;   11
            Magyar      (Hungarian)    ==&gt;   12
            polski      (Polish)       ==&gt;   13
            Romaneste   (Romanian)     ==&gt;   14</code></pre>

<p>See the section &quot;How to install additional languages&quot; in the file &quot;INSTALL.txt&quot; in this distribution for how to add more languages to this package.</p>

<p>In the original distribution (no other languages installed), the following examples will all return the value &quot;<code>3</code>&quot;:</p>

<pre><code>  $lang = Decode_Language(&quot;d&quot;);
  $lang = Decode_Language(&quot;de&quot;);
  $lang = Decode_Language(&quot;Deutsch&quot;);</code></pre>

<p>Note that you may not be able to enter the special international characters in some of the languages&#39; names over the keyboard directly on some systems.</p>

<p>This should never be a problem, though; just enter an abbreviation of the name of the language consisting of the first few letters up to the character before the first special international character.</p>

</li>
<li><p><code>if (($year,$month,$day) = Decode_Date_EU($string[,$lang]))</code></p>

<p>This function scans a given string and tries to parse any date which might be embedded in it.</p>

<p>The function returns an empty list if it can&#39;t successfully extract a valid date from its input string, or else it returns the date found.</p>

<p>The function accepts almost any format, as long as the date is given in the european order (hence its name) day-month-year.</p>

<p>Thereby, zero or more <b>NON-NUMERIC</b> characters may <b>PRECEDE</b> the day and <b>FOLLOW</b> the year.</p>

<p>Moreover, zero or more <b>NON-ALPHANUMERIC</b> characters are permitted <b>BETWEEN</b> these three items (i.e., between day and month and between month and year).</p>

<p>The month may be given either numerically (i.e., a number from &quot;<code>1</code>&quot; to &quot;<code>12</code>&quot;), or alphanumerically, i.e., as the name of the month in the given or currently selected language, or any uniquely identifying abbreviation thereof.</p>

<p>(See further below for details about the multi-language support of this package!)</p>

<p>If the year is given as one or two digits only (i.e., if the year is less than 100), it is mapped to a &quot;window&quot; of +/- 50 years around the current year, as described by the &quot;Moving_Window()&quot; function (see further below).</p>

<p>If the day, month and year are all given numerically but <b>WITHOUT</b> any delimiting characters between them, this string of digits will be mapped to the day, month and year as follows:</p>

<pre><code>                Length:        Mapping:
                  3              dmy
                  4              dmyy
                  5              dmmyy
                  6              ddmmyy
                  7              dmmyyyy
                  8              ddmmyyyy</code></pre>

<p>(Where &quot;d&quot; stands for &quot;day&quot;, &quot;m&quot; stands for &quot;month&quot; and &quot;y&quot; stands for &quot;year&quot;.)</p>

<p>All other strings consisting purely of digits (without any intervening delimiters) are rejected, i.e., not recognized.</p>

<p>Examples:</p>

<pre><code>  &quot;3.1.64&quot;
  &quot;3 1 64&quot;
  &quot;03.01.64&quot;
  &quot;03/01/64&quot;
  &quot;3. Jan 1964&quot;
  &quot;Birthday: 3. Jan &#39;64 in Backnang/Germany&quot;
  &quot;03-Jan-64&quot;
  &quot;3.Jan1964&quot;
  &quot;3Jan64&quot;
  &quot;030164&quot;
  &quot;3ja64&quot;
  &quot;3164&quot;</code></pre>

<p>Experiment! (See the corresponding example applications in the &quot;examples&quot; subdirectory of this distribution in order to do so.)</p>

</li>
<li><p><code>if (($year,$month,$day) = Decode_Date_US($string[,$lang]))</code></p>

<p>This function scans a given string and tries to parse any date which might be embedded in it.</p>

<p>The function returns an empty list if it can&#39;t successfully extract a valid date from its input string, or else it returns the date found.</p>

<p>The function accepts almost any format, as long as the date is given in the U.S. american order (hence its name) month-day-year.</p>

<p>Thereby, zero or more <b>NON-ALPHANUMERIC</b> characters may <b>PRECEDE</b> and <b>FOLLOW</b> the month (i.e., precede the month and separate it from the day which follows behind).</p>

<p>Moreover, zero or more <b>NON-NUMERIC</b> characters are permitted <b>BETWEEN</b> the day and the year, as well as <b>AFTER</b> the year.</p>

<p>The month may be given either numerically (i.e., a number from &quot;<code>1</code>&quot; to &quot;<code>12</code>&quot;), or alphanumerically, i.e., as the name of the month in the given or currently selected language, or any uniquely identifying abbreviation thereof.</p>

<p>(See further below for details about the multi-language support of this package!)</p>

<p>If the year is given as one or two digits only (i.e., if the year is less than 100), it is mapped to a &quot;window&quot; of +/- 50 years around the current year, as described by the &quot;Moving_Window()&quot; function (see further below).</p>

<p>If the month, day and year are all given numerically but <b>WITHOUT</b> any delimiting characters between them, this string of digits will be mapped to the month, day and year as follows:</p>

<pre><code>                Length:        Mapping:
                  3              mdy
                  4              mdyy
                  5              mddyy
                  6              mmddyy
                  7              mddyyyy
                  8              mmddyyyy</code></pre>

<p>(Where &quot;m&quot; stands for &quot;month&quot;, &quot;d&quot; stands for &quot;day&quot; and &quot;y&quot; stands for &quot;year&quot;.)</p>

<p>All other strings consisting purely of digits (without any intervening delimiters) are rejected, i.e., not recognized.</p>

<p>If only the day and the year form a contiguous string of digits, they will be mapped as follows:</p>

<pre><code>                Length:        Mapping:
                  2              dy
                  3              dyy
                  4              ddyy
                  5              dyyyy
                  6              ddyyyy</code></pre>

<p>(Where &quot;d&quot; stands for &quot;day&quot; and &quot;y&quot; stands for &quot;year&quot;.)</p>

<p>Examples:</p>

<pre><code>  &quot;1 3 64&quot;
  &quot;01/03/64&quot;
  &quot;Jan 3 &#39;64&quot;
  &quot;Jan 3 1964&quot;
  &quot;===&gt; January 3rd 1964 (birthday)&quot;
  &quot;Jan31964&quot;
  &quot;Jan364&quot;
  &quot;ja364&quot;
  &quot;1364&quot;</code></pre>

<p>Experiment! (See the corresponding example applications in the &quot;examples&quot; subdirectory of this distribution in order to do so.)</p>

</li>
<li><p><code>$year = Fixed_Window($yy);</code></p>

<p>This function applies a &quot;fixed window&quot; strategy to two-digit year numbers in order to convert them into four-digit year numbers.</p>

<p>All other year numbers are passed through unchanged, except for negative year numbers, which cause the function to return zero (&quot;<code>0</code>&quot;) instead.</p>

<p>Two-digit year numbers &quot;<code>yy</code>&quot; below 70 are converted to &quot;<code>20yy</code>&quot;, whereas year numbers equal to or greater than 70 (but less than 100) are converted to &quot;<code>19yy</code>&quot;.</p>

<p>In the original distribution of this package, the base century is set to &quot;1900&quot; and the base year to &quot;70&quot; (which is a standard on UNIX systems), but these constants (also called the &quot;epoch&quot;) can actually be chosen at will.</p>

</li>
<li><p><code>$year = Moving_Window($yy);</code></p>

<p>This function applies a &quot;moving window&quot; strategy to two-digit year numbers in order to convert them into four-digit year numbers, provided the necessary system calls (system clock) are available. Otherwise the function falls back to the &quot;fixed window&quot; strategy described in the function above.</p>

<p>All other year numbers are passed through unchanged, except for negative year numbers, which cause the function to return zero (&quot;<code>0</code>&quot;) instead.</p>

<p>Two-digit year numbers are mapped according to a &quot;window&quot; of 50 years in both directions (past and future) around the current year.</p>

<p>That is, two-digit year numbers are first mapped to the same century as the current year. If the resulting year is smaller than the current year minus 50, then one more century is added to the result. If the resulting year is equal to or greater than the current year plus 50, then a century is subtracted from the result.</p>

</li>
<li><p><code>$date = Compress($year,$month,$day);</code></p>

<p>WARNING: This function is legacy code, its use is deprecated!</p>

<p>This function encodes a date in 16 bits, which is the value being returned.</p>

<p>The encoding scheme is as follows:</p>

<pre><code>            Bit number:    FEDCBA9 8765 43210
            Contents:      yyyyyyy mmmm ddddd</code></pre>

<p>(Where the &quot;yyyyyyy&quot; contain the number of the year, &quot;mmmm&quot; the number of the month and &quot;ddddd&quot; the number of the day.)</p>

<p>The function returns &quot;<code>0</code>&quot; if the given input values do not represent a valid date. Therefore, the return value of this function can also be used as the conditional expression in an &quot;if&quot; statement, in order to check whether the given input values constitute a valid date).</p>

<p>Through this special encoding scheme, it is possible to <b>COMPARE</b> compressed dates for equality and order (less than/greater than) <b>WITHOUT</b> any previous <b>DECODING</b>!</p>

<p>Note however that contiguous dates do <b>NOT</b> necessarily have contiguous compressed representations!</p>

<p>I.e., incrementing the compressed representation of a date <b>MAY OR MAY NOT</b> yield a valid new date!</p>

<p>Note also that this function can only handle dates within one century.</p>

<p>This century can be chosen at will (at compile time of this module) by defining a base century and year (also called the &quot;epoch&quot;). In the original distribution of this package, the base century is set to &quot;1900&quot; and the base year to &quot;70&quot; (which is standard on UNIX systems).</p>

<p>This allows this function to handle dates from &quot;1970&quot; up to &quot;2069&quot;.</p>

<p>If the given year is equal to, say, &quot;95&quot;, this package will automatically assume that you really meant &quot;1995&quot; instead. However, if you specify a year number which is <b>SMALLER</b> than 70, like &quot;64&quot;, for instance, this package will assume that you really meant &quot;2064&quot;.</p>

<p>You are not confined to two-digit (abbreviated) year numbers, though.</p>

<p>The function also accepts &quot;full-length&quot; year numbers, provided that they lie in the supported range (i.e., from &quot;1970&quot; to &quot;2069&quot;, in the original configuration of this package).</p>

<p>Note that this function is maintained mainly for backward compatibility, and that its use is not recommended.</p>

</li>
<li><p><code>if (($century,$year,$month,$day) = Uncompress($date))</code></p>

<p>WARNING: This function is legacy code, its use is deprecated!</p>

<p>This function decodes dates that were encoded previously using the function &quot;<code>Compress()</code>&quot;.</p>

<p>It returns the century, year, month and day of the date encoded in &quot;<code>$date</code>&quot; if &quot;<code>$date</code>&quot; represents a valid date, or an empty list otherwise.</p>

<p>The year returned in &quot;<code>$year</code>&quot; is actually a two-digit year number (i.e., the year number taken modulo 100), and only the expression &quot;<code>$century + $year</code>&quot; yields the &quot;full-length&quot; year number (for example, <code>1900 + 95 = 1995</code>).</p>

<p>Note that this function is maintained mainly for backward compatibility, and that its use is not recommended.</p>

</li>
<li><p><code>if (check_compressed($date))</code></p>

<p>WARNING: This function is legacy code, its use is deprecated!</p>

<p>This function returns &quot;true&quot; (&quot;<code>1</code>&quot;) if the given input value constitutes a valid compressed date, and &quot;false&quot; (&quot;<code>0</code>&quot;) otherwise.</p>

<p>Note that this function is maintained mainly for backward compatibility, and that its use is not recommended.</p>

</li>
<li><p><code>$string = Compressed_to_Text($date[,$lang]);</code></p>

<p>WARNING: This function is legacy code, its use is deprecated!</p>

<p>This function returns a string of fixed length (always 9 characters long) containing a textual representation of the compressed date encoded in &quot;<code>$date</code>&quot;.</p>

<p>This string has the form &quot;dd-Mmm-yy&quot;, where &quot;dd&quot; is the two-digit number of the day, &quot;Mmm&quot; are the first three letters of the name of the month in the given or currently selected language (see further below for details about the multi-language support of this package), and &quot;yy&quot; is the two-digit year number (i.e., the year number taken modulo 100).</p>

<p>If &quot;<code>$date</code>&quot; does not represent a valid date, the string &quot;??-???-??&quot; is returned instead.</p>

<p>Note that this function is maintained mainly for backward compatibility, and that its use is not recommended.</p>

</li>
<li><p><code>$string = Date_to_Text($year,$month,$day[,$lang]);</code></p>

<p>This function returns a string containing a textual representation of the given date of the form &quot;www dd-Mmm-yyyy&quot;, where &quot;www&quot; are the first three letters of the name of the day of week in the given or currently selected language, or a special abbreviation, if special abbreviations have been defined for the given or currently selected language (see further below for details about the multi-language support of this package), &quot;dd&quot; is the day (one or two digits), &quot;Mmm&quot; are the first three letters of the name of the month in the given or currently selected language, and &quot;yyyy&quot; is the number of the year in full length.</p>

<p>If the given input values do not constitute a valid date, a fatal &quot;not a valid date&quot; error occurs.</p>

<p>(See the section &quot;RECIPES&quot; near the end of this document for a code snippet for how to print dates in any format you like.)</p>

</li>
<li><p><code>$string = Date_to_Text_Long($year,$month,$day[,$lang]);</code></p>

<p>This function returns a string containing a textual representation of the given date roughly of the form &quot;Wwwwww, dd Mmmmmm yyyy&quot;, where &quot;Wwwwww&quot; is the name of the day of week in the given or currently selected language (see further below for details about the multi-language support of this package), &quot;dd&quot; is the day (one or two digits), &quot;Mmmmmm&quot; is the name of the month in the given or currently selected language, and &quot;yyyy&quot; is the number of the year in full length.</p>

<p>The exact format of the output string depends on the given or currently selected language. In the original distribution of this package, these formats are defined as follows:</p>

<pre><code>  1  English    :  &quot;Wwwwww, Mmmmmm ddth yyyy&quot;
  2  French     :  &quot;Wwwwww dd mmmmmm yyyy&quot;
  3  German     :  &quot;Wwwwww, den dd. Mmmmmm yyyy&quot;
  4  Spanish    :  &quot;Wwwwww, dd de mmmmmm de yyyy&quot;
  5  Portuguese :  &quot;Wwwwww, dia dd de mmmmmm de yyyy&quot;
  6  Dutch      :  &quot;Wwwwww, dd mmmmmm yyyy&quot;
  7  Italian    :  &quot;Wwwwww, dd Mmmmmm yyyy&quot;
  8  Norwegian  :  &quot;wwwwww, dd. mmmmmm yyyy&quot;
  9  Swedish    :  &quot;wwwwww, dd mmmmmm yyyy&quot;
 10  Danish     :  &quot;wwwwww, dd. mmmmmm yyyy&quot;
 11  Finnish    :  &quot;wwwwww, dd. mmmmmmta yyyy&quot;
 12  Hungarian  :  &quot;dd. Mmmmmm yyyy., wwwwww&quot;
 13  Polish     :  &quot;Wwwwww, dd Mmmmmm yyyy&quot;
 14  Romanian   :  &quot;Wwwwww dd Mmmmmm yyyy&quot;</code></pre>

<p>(You can change these formats in the file &quot;Pcalc.pm&quot; before installing this module in order to suit your personal preferences.)</p>

<p>If the given input values do not constitute a valid date, a fatal &quot;not a valid date&quot; error occurs.</p>

<p>In order to capitalize the day of week at the beginning of the string in Norwegian, use &quot;<code>ucfirst(Date_to_Text_Long($year,$month,$day,8));</code>&quot;.</p>

<p>(See the section &quot;RECIPES&quot; near the end of this document for an example on how to print dates in any format you like.)</p>

</li>
<li><p><code>$string = English_Ordinal($number);</code></p>

<p>This function returns a string containing the (english) abbreviation of the ordinal number for the given (cardinal) number &quot;<code>$number</code>&quot;.</p>

<p>I.e.,</p>

<pre><code>    0  =&gt;  &#39;0th&#39;    10  =&gt;  &#39;10th&#39;    20  =&gt;  &#39;20th&#39;
    1  =&gt;  &#39;1st&#39;    11  =&gt;  &#39;11th&#39;    21  =&gt;  &#39;21st&#39;
    2  =&gt;  &#39;2nd&#39;    12  =&gt;  &#39;12th&#39;    22  =&gt;  &#39;22nd&#39;
    3  =&gt;  &#39;3rd&#39;    13  =&gt;  &#39;13th&#39;    23  =&gt;  &#39;23rd&#39;
    4  =&gt;  &#39;4th&#39;    14  =&gt;  &#39;14th&#39;    24  =&gt;  &#39;24th&#39;
    5  =&gt;  &#39;5th&#39;    15  =&gt;  &#39;15th&#39;    25  =&gt;  &#39;25th&#39;
    6  =&gt;  &#39;6th&#39;    16  =&gt;  &#39;16th&#39;    26  =&gt;  &#39;26th&#39;
    7  =&gt;  &#39;7th&#39;    17  =&gt;  &#39;17th&#39;    27  =&gt;  &#39;27th&#39;
    8  =&gt;  &#39;8th&#39;    18  =&gt;  &#39;18th&#39;    28  =&gt;  &#39;28th&#39;
    9  =&gt;  &#39;9th&#39;    19  =&gt;  &#39;19th&#39;    29  =&gt;  &#39;29th&#39;</code></pre>

<p>etc.</p>

</li>
<li><p><code>$string = Calendar($year,$month[,$orthodox[,$lang]]);</code></p>

<p>This function returns a calendar of the given month in the given year (somewhat similar to the UNIX &quot;<code>cal</code>&quot; command), in the given or currently selected language (see further below for details about the multi-language support of this package).</p>

<p>Example:</p>

<pre><code>  print Calendar(1998,5);</code></pre>

<p>This will print:</p>

<pre><code>           May 1998
  Mon Tue Wed Thu Fri Sat Sun
                    1   2   3
    4   5   6   7   8   9  10
   11  12  13  14  15  16  17
   18  19  20  21  22  23  24
   25  26  27  28  29  30  31</code></pre>

<p>If the optional boolean parameter &quot;<code>$orthodox</code>&quot; is given and true, the calendar starts on Sunday instead of Monday.</p>

</li>
<li><p><code>$string = Month_to_Text($month[,$lang]);</code></p>

<p>This function returns the name of the given month in the given or currently selected language (see further below for details about the multi-language support of this package).</p>

<p>If the given month lies outside of the valid range from &quot;<code>1</code>&quot; to &quot;<code>12</code>&quot;, a fatal &quot;month out of range&quot; error will occur.</p>

</li>
<li><p><code>$string = Day_of_Week_to_Text($dow[,$lang]);</code></p>

<p>This function returns the name of the given day of week in the given or currently selected language (see further below for details about the multi-language support of this package).</p>

<p>If the given day of week lies outside of the valid range from &quot;<code>1</code>&quot; to &quot;<code>7</code>&quot;, a fatal &quot;day of week out of range&quot; error will occur.</p>

</li>
<li><p><code>$string = Day_of_Week_Abbreviation($dow[,$lang]);</code></p>

<p>This function returns the special abbreviation of the name of the given day of week, <b>IF</b> such special abbreviations have been defined for the given or currently selected language (see further below for details about the multi-language support of this package).</p>

<p>(In the original distribution of this package, this was only true for Portuguese. Starting with version 5.1, abbreviations for Polish have also been introduced. Starting with version 5.7, the abbreviations for Portuguese have been disabled. So Polish is currently the only language to define such special abbreviations.)</p>

<p>If not, the first three letters of the name of the day of week in the given or currently selected language are returned instead.</p>

<p>If the given day of week lies outside of the valid range from &quot;<code>1</code>&quot; to &quot;<code>7</code>&quot;, a fatal &quot;day of week out of range&quot; error will occur.</p>

<p>Currently, this table of special abbreviations is only used by the functions &quot;<code>Date_to_Text()</code>&quot; and &quot;<code>Calendar()</code>&quot;, internally.</p>

</li>
<li><p><code>$string = Language_to_Text($lang);</code></p>

<p>This function returns the name of any language supported by this package when the internal number representing that language is given as input.</p>

<p>The original distribution supports the following fourteen languages:</p>

<pre><code>            1   ==&gt;   English                     (default)
            2   ==&gt;   Fran&ccedil;ais    (French)
            3   ==&gt;   Deutsch     (German)
            4   ==&gt;   Espa&ntilde;ol     (Spanish)
            5   ==&gt;   Portugu&ecirc;s   (Portuguese)
            6   ==&gt;   Nederlands  (Dutch)
            7   ==&gt;   Italiano    (Italian)
            8   ==&gt;   Norsk       (Norwegian)
            9   ==&gt;   Svenska     (Swedish)
           10   ==&gt;   Dansk       (Danish)
           11   ==&gt;   suomi       (Finnish)
           12   ==&gt;   Magyar      (Hungarian)
           13   ==&gt;   polski      (Polish)
           14   ==&gt;   Romaneste   (Romanian)</code></pre>

<p>See the section &quot;How to install additional languages&quot; in the file &quot;INSTALL.txt&quot; in this distribution for how to add more languages to this package.</p>

<p>See the description of the function &quot;<code>Languages()</code>&quot; further below to determine how many languages are actually available in a given installation of this package.</p>

</li>
<li><p><code>$lang = Language();</code></p>

</li>
<li><p><code>Language($lang); # DEPRECATED</code></p>

</li>
<li><p><code>$oldlang = Language($newlang); # DEPRECATED</code></p>

<p>This function can be used to determine which language is currently selected, and to change the selected language (this latter use is deprecated, because this global setting may cause conflicts between threads or modules running concurrently).</p>

<p>Thereby, each language has a unique internal number.</p>

<p>The original distribution contains the following fourteen languages:</p>

<pre><code>            1   ==&gt;   English                     (default)
            2   ==&gt;   Fran&ccedil;ais    (French)
            3   ==&gt;   Deutsch     (German)
            4   ==&gt;   Espa&ntilde;ol     (Spanish)
            5   ==&gt;   Portugu&ecirc;s   (Portuguese)
            6   ==&gt;   Nederlands  (Dutch)
            7   ==&gt;   Italiano    (Italian)
            8   ==&gt;   Norsk       (Norwegian)
            9   ==&gt;   Svenska     (Swedish)
           10   ==&gt;   Dansk       (Danish)
           11   ==&gt;   suomi       (Finnish)
           12   ==&gt;   Magyar      (Hungarian)
           13   ==&gt;   polski      (Polish)
           14   ==&gt;   Romaneste   (Romanian)</code></pre>

<p>See the section &quot;How to install additional languages&quot; in the file &quot;INSTALL.txt&quot; in this distribution for how to add more languages to this package.</p>

<p>See the description of the function &quot;<code>Languages()</code>&quot; further below to determine how many languages are actually available in a given installation of this package.</p>

<p><b>BEWARE</b> that in order for your programs to be portable, you should <b>NEVER</b> actually use the internal number of a language in this package <b>EXPLICITLY</b>, because the same number could mean different languages on different systems, depending on what languages have been added to any given installation of this package.</p>

<p>Therefore, you should always use a statement such as</p>

<pre><code>  Language(Decode_Language(&quot;Name_of_Language&quot;)); # DEPRECATED</code></pre>

<p>or</p>

<pre><code>  DateCalc_Function(@parameters,Decode_Language(&quot;Name_of_Language&quot;)); # RECOMMENDED</code></pre>

<p>to select the desired language, and</p>

<pre><code>  $language = Language_to_Text(Language());</code></pre>

<p>or</p>

<pre><code>  $old_language = Language_to_Text(Language(&quot;Name_of_new_Language&quot;)); # DEPRECATED</code></pre>

<p>to determine the (previously) selected language.</p>

<p>If the so chosen language is not available in the current installation, this will result in an appropriate error message, instead of silently using the wrong (a random) language (which just happens to have the same internal number in the other installation).</p>

<p><b>BEWARE</b> that when using the function &quot;<code>Language()</code>&quot;, the selected language is a global setting, shared by all threads or modules you might be running concurrently, thus possibly causing conflicts between them.</p>

<p>In order to avoid these conflicts, you should <b>NEVER</b> use the function &quot;<code>Language()</code>&quot;, but should <b>ALWAYS</b> pass a language number (as returned by the function &quot;<code>Decode_Language()</code>&quot;) to the functions which are language-dependent, which are:</p>

<p>&quot;Decode_Month()&quot;, &quot;Decode_Day_of_Week()&quot;, &quot;Compressed_to_Text()&quot;, &quot;Date_to_Text()&quot;, &quot;Date_to_Text_Long()&quot;, &quot;Calendar()&quot;, &quot;Month_to_Text()&quot;, &quot;Day_of_Week_to_Text()&quot;, &quot;Day_of_Week_Abbreviation()&quot;, &quot;Decode_Date_EU()&quot;, &quot;Decode_Date_US()&quot;, &quot;Decode_Date_EU2()&quot;, &quot;Decode_Date_US2()&quot;, &quot;Parse_Date()&quot;.</p>

<p>Note that when you pass an invalid number, such as e.g. zero, or no language parameter at all, these functions will revert to their behaviour in the versions of this module prior to 6.0, which means that the global setting (as set by &quot;<code>Language()</code>&quot;) becomes active again (only in case of an invalid or missing language parameter!).</p>

</li>
<li><p><code>$max_lang = Languages();</code></p>

<p>This function returns the (maximum) number of languages which are currently available in your installation of this package.</p>

<p>(This may vary from installation to installation.)</p>

<p>See the section &quot;How to install additional languages&quot; in the file &quot;INSTALL.txt&quot; in this distribution for how to add more languages to this package.</p>

<p>In the original distribution of this package there are fourteen built-in languages, therefore the value returned by this function will be &quot;<code>14</code>&quot; if no other languages have been added to your particular installation.</p>

</li>
<li><p><code>if (($year,$month,$day) = Decode_Date_EU2($string[,$lang))</code></p>

<p>This function is the more &quot;Perlish&quot; equivalent of the function &quot;<code>Decode_Date_EU()</code>&quot; (translated from C), included here merely as an example to demonstrate how easy it is to write your own routine in Perl (using regular expressions) adapted to your own special needs, should the necessity arise, and intended primarily as a basis for your own development.</p>

<p>In one particular case this more &quot;Perlish&quot; version is actually slightly more permissive than its equivalent (translated from C), as far as the class of permitted intervening (i.e., delimiting) characters is concerned.</p>

<p>(Can you tell the subtle, almost insignificant difference by looking at the code? Or by experimenting? Hint: Try the string &quot;a3b1c64d&quot; with both functions.)</p>

</li>
<li><p><code>if (($year,$month,$day) = Decode_Date_US2($string[,$lang))</code></p>

<p>This function is the more &quot;Perlish&quot; equivalent of the function &quot;<code>Decode_Date_US()</code>&quot; (translated from C), included here merely as an example to demonstrate how easy it is to write your own routine in Perl (using regular expressions) adapted to your own special needs, should the necessity arise, and intended primarily as a basis for your own development.</p>

<p>In one particular case this more &quot;Perlish&quot; version is actually slightly more permissive than its equivalent (translated from C).</p>

<p>(Hint: This is the same difference as with the &quot;<code>Decode_Date_EU()</code>&quot; and &quot;<code>Decode_Date_EU2()</code>&quot; pair of functions.)</p>

<p>In a different case, the version translated from C is a little bit more permissive than its Perl equivalent.</p>

<p>(Can you tell the difference by looking at the code? Or by experimenting? Hint: Try the string &quot;(1/364)&quot; with both functions.)</p>

</li>
<li><p><code>if (($year,$month,$day) = Parse_Date($string[,$lang))</code></p>

<p>This function is useful for parsing dates as returned by the UNIX &quot;<code>date</code>&quot; command or as found in the headers of e-mail (in order to determine the date at which some e-mail has been sent or received, for instance).</p>

<p>Example #1:</p>

<pre><code>  ($year,$month,$day) = Parse_Date(`/bin/date`);</code></pre>

<p>Example #2:</p>

<pre><code>  while (&lt;MAIL&gt;)
  {
      if (/^From \S/)
      {
          ($year,$month,$day) = Parse_Date($_);
          ...
      }
      ...
  }</code></pre>

<p>The function returns an empty list if it can&#39;t extract a valid date from the input string.</p>

</li>
<li><p><code>$lower = ISO_LC($string);</code></p>

<p>Returns a copy of the given string where all letters of the ISO-Latin-1 character set have been replaced by their lower case equivalents.</p>

<p>Similar to Perl&#39;s built-in function &quot;<code>lc()</code>&quot; (see <a href="http://man.he.net/man1/perlfunc">&quot;lc&quot; in perlfunc(1)</a>) but for the whole ISO-Latin-1 character set, not just plain ASCII.</p>

</li>
<li><p><code>$upper = ISO_UC($string);</code></p>

<p>Returns a copy of the given string where all letters of the ISO-Latin-1 character set have been replaced by their upper case equivalents.</p>

<p>Similar to Perl&#39;s built-in function &quot;<code>uc()</code>&quot; (see <a href="http://man.he.net/man1/perlfunc">&quot;uc&quot; in perlfunc(1)</a>) but for the whole ISO-Latin-1 character set, not just plain ASCII.</p>

</li>
<li><p><code>$string = Date::Pcalc::Version();</code></p>

<p>This function returns a string with the (numeric) version number of the file &quot;Pcalc.pm&quot; at the core of this package.</p>

<p>Note that under all normal circumstances, this version number should be identical with the one found in the Perl variable &quot;<code>$Date::Pcalc::VERSION</code>&quot; (the version number of the &quot;Pcalc.pm&quot; file).</p>

<p>Since this function is not exported, you always have to qualify it explicitly, i.e., &quot;<code>Date::Pcalc::Version()</code>&quot;.</p>

<p>This is to avoid possible name space conflicts with version functions from other modules.</p>

</li>
</ul>

<h1 id="RECIPES">RECIPES</h1>

<dl>

<dt id="1)"><a id="1"></a><a id="pod"></a>1)</dt>
<dd>

<p>How do I compare two dates?</p>

<p>Solution #1:</p>

<pre><code>  use Date::Pcalc qw( Date_to_Days );

  if (Date_to_Days($year1,$month1,$day1)  &lt;
      Date_to_Days($year2,$month2,$day2))

  if (Date_to_Days($year1,$month1,$day1)  &lt;=
      Date_to_Days($year2,$month2,$day2))

  if (Date_to_Days($year1,$month1,$day1)  &gt;
      Date_to_Days($year2,$month2,$day2))

  if (Date_to_Days($year1,$month1,$day1)  &gt;=
      Date_to_Days($year2,$month2,$day2))

  if (Date_to_Days($year1,$month1,$day1)  ==
      Date_to_Days($year2,$month2,$day2))

  if (Date_to_Days($year1,$month1,$day1)  !=
      Date_to_Days($year2,$month2,$day2))

  $cmp = (Date_to_Days($year1,$month1,$day1)  &lt;=&gt;
          Date_to_Days($year2,$month2,$day2));</code></pre>

<p>Solution #2:</p>

<pre><code>  use Date::Pcalc qw( Delta_Days );

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) &gt; 0)

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) &gt;= 0)

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) &lt; 0)

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) &lt;= 0)

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) == 0)

  if (Delta_Days($year1,$month1,$day1,
                 $year2,$month2,$day2) != 0)</code></pre>

</dd>
<dt id="2)"><a id="2"></a><a id="pod1"></a>2)</dt>
<dd>

<p>How do I check whether a given date lies within a certain range of dates?</p>

<pre><code>  use Date::Pcalc qw( Date_to_Days );

  $lower = Date_to_Days($year1,$month1,$day1);
  $upper = Date_to_Days($year2,$month2,$day2);

  $date = Date_to_Days($year,$month,$day);

  if (($date &gt;= $lower) &amp;&amp; ($date &lt;= $upper))
  {
      # ok
  }
  else
  {
      # not ok
  }</code></pre>

</dd>
<dt id="3)"><a id="3"></a><a id="pod2"></a>3)</dt>
<dd>

<p>How do I compare two dates with times? How do I check whether two dates and times lie more or less than a given time interval apart?</p>

<p>Solution #1:</p>

<pre><code>  use Date::Pcalc qw( Add_Delta_DHMS Date_to_Days );

  @date1 = (2002,8,31,23,59,1);
  @date2 = (2002,9,1,11,30,59); # ==&gt; less than 12 hours

  #@date1 = (2002,8,31,22,59,1);
  #@date2 = (2002,9,1,11,30,59); # ==&gt; more than 12 hours

  # Omit the next line if you just want to compare the two dates
  # (and change @date3 and @d3 to @date1 and @d1, respectively):

  @date3 = Add_Delta_DHMS(@date1, 0,12,0,0); # ==&gt; is the difference within 12 hours?

  @d2 = ( Date_to_Days(@date2[0..2]), ($date2[3]*60+$date2[4])*60+$date2[5] );
  @d3 = ( Date_to_Days(@date3[0..2]), ($date3[3]*60+$date3[4])*60+$date3[5] );

  @diff = ( $d2[0]-$d3[0], $d2[1]-$d3[1] );

  if ($diff[0] &gt; 0 and $diff[1] &lt; 0) { $diff[0]--; $diff[1] += 86400; }
  if ($diff[0] &lt; 0 and $diff[1] &gt; 0) { $diff[0]++; $diff[1] -= 86400; }

  if (($diff[0] || $diff[1]) &gt;= 0) { print &quot;More than 12 hours.\n&quot;; }
  else                             { print &quot;Less than 12 hours.\n&quot;; }</code></pre>

<p>Solution #2:</p>

<p>This solution is only feasible if your dates are guaranteed to lie within the range given by your system&#39;s epoch and overflow date and time!</p>

<pre><code>     Unix:    1-Jan-1970 00:00:00  to  19-Jan-2038 03:14:07
     MacOS:   1-Jan-1904 00:00:00  to   6-Feb-2040 06:28:15

  use Date::Pcalc qw( Date_to_Time );

  @date1 = (2002,8,31,23,59,1);
  @date2 = (2002,9,1,11,30,59); # ==&gt; less than 12 hours

  #@date1 = (2002,8,31,22,59,1);
  #@date2 = (2002,9,1,11,30,59); # ==&gt; more than 12 hours

  $d1 = Date_to_Time(@date1);
  $d2 = Date_to_Time(@date2);

  if ($d1 &lt;= $d2) { print &quot;The two dates are in chronological order.\n&quot;; }
  else            { print &quot;The two dates are in reversed order.\n&quot;; }

  if ($d1 + 12*60*60 &lt;= $d2) { print &quot;More than 12 hours.\n&quot;; }
  else                       { print &quot;Less than 12 hours.\n&quot;; }</code></pre>

</dd>
<dt id="4)"><a id="4"></a><a id="pod3"></a>4)</dt>
<dd>

<p>How do I verify whether someone has a certain age?</p>

<pre><code>  use Date::Pcalc qw( Decode_Date_EU Today leap_year Delta_Days );

  $date = &lt;STDIN&gt;; # get birthday

  ($year1,$month1,$day1) = Decode_Date_EU($date);

  ($year2,$month2,$day2) = Today();

  if (($day1 == 29) &amp;&amp; ($month1 == 2) &amp;&amp; !leap_year($year2))
      { $day1--; }

  if ( (($year2 - $year1) &gt;  18) ||
     ( (($year2 - $year1) == 18) &amp;&amp;
     (Delta_Days($year2,$month1,$day1, $year2,$month2,$day2) &gt;= 0) ) )
  {
      print &quot;Ok - you are over 18.\n&quot;;
  }
  else
  {
      print &quot;Sorry - you aren&#39;t 18 yet!\n&quot;;
  }

  Or, alternatively (substituting the last &quot;if&quot; statement above):

  if (($year1+18 &lt;=&gt; $year2 || $month1 &lt;=&gt; $month2 || $day1 &lt;=&gt; $day2) &lt;= 0)
      { print &quot;Ok - you are over 18.\n&quot;; }
  else
      { print &quot;Sorry - you aren&#39;t 18 yet!\n&quot;; }</code></pre>

</dd>
<dt id="5)"><a id="5"></a><a id="pod4"></a>5)</dt>
<dd>

<p>How do I calculate the number of the week of month the current date lies in?</p>

<p>For example:</p>

<pre><code>            April 1998
    Mon Tue Wed Thu Fri Sat Sun
              1   2   3   4   5  =  week #1
      6   7   8   9  10  11  12  =  week #2
     13  14  15  16  17  18  19  =  week #3
     20  21  22  23  24  25  26  =  week #4
     27  28  29  30              =  week #5</code></pre>

<p>Solution:</p>

<pre><code>  use Date::Pcalc qw( Today Day_of_Week );

  ($year,$month,$day) = Today();

  $week = int(($day + Day_of_Week($year,$month,1) - 2) / 7) + 1;</code></pre>

</dd>
<dt id="6)"><a id="6"></a><a id="pod5"></a>6)</dt>
<dd>

<p>How do I calculate whether a given date is the 1st, 2nd, 3rd, 4th or 5th of that day of week in the given month?</p>

<p>For example:</p>

<pre><code>           October 2000
    Mon Tue Wed Thu Fri Sat Sun
                              1
      2   3   4   5   6   7   8
      9  10  11  12  13  14  15
     16  17  18  19  20  21  22
     23  24  25  26  27  28  29
     30  31</code></pre>

<p>Is Sunday, the 15th of October 2000, the 1st, 2nd, 3rd, 4th or 5th Sunday of that month?</p>

<p>Solution:</p>

<pre><code>  use Date::Pcalc qw( Day_of_Week Delta_Days
                      Nth_Weekday_of_Month_Year
                      Date_to_Text_Long English_Ordinal
                      Day_of_Week_to_Text Month_to_Text );

  ($year,$month,$day) = (2000,10,15);

  $dow = Day_of_Week($year,$month,$day);

  $n = int( Delta_Days(
            Nth_Weekday_of_Month_Year($year,$month,$dow,1),
            $year,$month,$day)
            / 7) + 1;

  printf(&quot;%s is the %s %s in %s %d.\n&quot;,
      Date_to_Text_Long($year,$month,$day),
      English_Ordinal($n),
      Day_of_Week_to_Text($dow),
      Month_to_Text($month),
      $year);</code></pre>

<p>This prints:</p>

<pre><code>  Sunday, October 15th 2000 is the 3rd Sunday in October 2000.</code></pre>

</dd>
<dt id="7)"><a id="7"></a><a id="pod6"></a>7)</dt>
<dd>

<p>How do I calculate the date of the Wednesday of the same week as the current date?</p>

<p>Solution #1:</p>

<pre><code>  use Date::Pcalc qw( Today Day_of_Week Add_Delta_Days );

  $searching_dow = 3; # 3 = Wednesday

  @today = Today();

  $current_dow = Day_of_Week(@today);

  @date = Add_Delta_Days(@today, $searching_dow - $current_dow);</code></pre>

<p>Solution #2:</p>

<pre><code>  use Date::Pcalc qw( Today Add_Delta_Days
                      Monday_of_Week Week_of_Year );

  $searching_dow = 3; # 3 = Wednesday

  @today = Today();

  @date = Add_Delta_Days( Monday_of_Week( Week_of_Year(@today) ),
                          $searching_dow - 1 );</code></pre>

<p>Solution #3:</p>

<pre><code>  use Date::Pcalc qw( Standard_to_Business Today
                      Business_to_Standard );

  @business = Standard_to_Business(Today());

  $business[2] = 3; # 3 = Wednesday

  @date = Business_to_Standard(@business);</code></pre>

</dd>
<dt id="8)"><a id="8"></a><a id="pod7"></a>8)</dt>
<dd>

<p>How can I add a week offset to a business date (including across year boundaries)?</p>

<pre><code>  use Date::Pcalc qw( Business_to_Standard Add_Delta_Days
                      Standard_to_Business );

  @temp = Business_to_Standard($year,$week,$dow);

  @temp = Add_Delta_Days(@temp, $week_offset * 7);

  ($year,$week,$dow) = Standard_to_Business(@temp);</code></pre>

</dd>
<dt id="9)"><a id="9"></a><a id="pod8"></a>9)</dt>
<dd>

<p>How do I calculate the last and the next Saturday for any given date?</p>

<pre><code>  use Date::Pcalc qw( Today Day_of_Week Add_Delta_Days
                      Day_of_Week_to_Text Date_to_Text );

  $searching_dow = 6; # 6 = Saturday

  @today = Today();

  $current_dow = Day_of_Week(@today);

  if ($searching_dow == $current_dow)
  {
      @prev = Add_Delta_Days(@today,-7);
      @next = Add_Delta_Days(@today,+7);
  }
  else
  {
      if ($searching_dow &gt; $current_dow)
      {
          @next = Add_Delta_Days(@today,
                    $searching_dow - $current_dow);
          @prev = Add_Delta_Days(@next,-7);
      }
      else
      {
          @prev = Add_Delta_Days(@today,
                    $searching_dow - $current_dow);
          @next = Add_Delta_Days(@prev,+7);
      }
  }

  $dow = Day_of_Week_to_Text($searching_dow);

  print &quot;Today is:      &quot;, &#39; &#39; x length($dow),
                               Date_to_Text(@today), &quot;\n&quot;;
  print &quot;Last $dow was:     &quot;, Date_to_Text(@prev),  &quot;\n&quot;;
  print &quot;Next $dow will be: &quot;, Date_to_Text(@next),  &quot;\n&quot;;</code></pre>

<p>This will print something like:</p>

<pre><code>  Today is:              Sun 12-Apr-1998
  Last Saturday was:     Sat 11-Apr-1998
  Next Saturday will be: Sat 18-Apr-1998</code></pre>

</dd>
<dt id="10)"><a id="10"></a><a id="pod9"></a>10)</dt>
<dd>

<p>How can I calculate the last business day (payday!) of a month?</p>

<p>Solution #1 (holidays <b>NOT</b> taken into account):</p>

<pre><code>  use Date::Pcalc qw( Days_in_Month Day_of_Week Add_Delta_Days );

  $day = Days_in_Month($year,$month);
  $dow = Day_of_Week($year,$month,$day);
  if ($dow &gt; 5)
  {
      ($year,$month,$day) =
          Add_Delta_Days($year,$month,$day, 5-$dow);
  }</code></pre>

<p>Solution #2 (holidays taken into account):</p>

<p>This solution expects a multi-dimensional array &quot;<code>@holiday</code>&quot;, which contains all holidays, as follows: &quot;<code>$holiday[$year][$month][$day] = 1;</code>&quot;.</p>

<p>(See the description of the function &quot;<code>Easter_Sunday()</code>&quot; further above for how to calculate the moving (variable) christian feast days!)</p>

<p>Days which are not holidays remain undefined or should have a value of zero in this array.</p>

<pre><code>  use Date::Pcalc qw( Days_in_Month Add_Delta_Days Day_of_Week );

  $day = Days_in_Month($year,$month);
  while (1)
  {
      while ($holiday[$year][$month][$day])
      {
          ($year,$month,$day) =
              Add_Delta_Days($year,$month,$day, -1);
      }
      $dow = Day_of_Week($year,$month,$day);
      if ($dow &gt; 5)
      {
          ($year,$month,$day) =
              Add_Delta_Days($year,$month,$day, 5-$dow);
      }
      else { last; }
  }</code></pre>

<p>Solution #3 (holidays taken into account, more comfortable, but requires Date::Pcalendar(3) and Date::Pcalc::Object(3)):</p>

<pre><code>  use Date::Pcalc::Object qw( Today Add_Delta_YM Date_to_Text_Long );
  use Date::Pcalendar::Profiles qw($Profiles);
  use Date::Pcalendar;

  $calendar = Date::Pcalendar-&gt;new( $Profiles-&gt;{&#39;DE-BW&#39;} );

  @today = Today();
  @nextmonth = Add_Delta_YM(@today[0,1],1, 0,1);

  $workaround = $calendar-&gt;add_delta_workdays(@nextmonth,+1);
  $payday     = $calendar-&gt;add_delta_workdays($workaround,-2);

  print &quot;Pay day = &quot;, Date_to_Text_Long($payday-&gt;date()), &quot;\n&quot;;</code></pre>

<p>The &quot;workaround&quot; is necessary due to a bug in the method &quot;add_delta_workdays()&quot; when adding a negative number of workdays.</p>

</dd>
<dt id="11)"><a id="11"></a><a id="pod10"></a>11)</dt>
<dd>

<p>How do I convert a MS Visual Basic &quot;DATETIME&quot; value into its date and time constituents?</p>

<pre><code>  use Date::Pcalc qw( Add_Delta_DHMS Date_to_Text );

  $datetime = &quot;35883.121653&quot;;

  ($Dd,$Dh,$Dm,$Ds) = ($datetime =~ /^(\d+)\.(\d\d)(\d\d)(\d\d)$/);

  ($year,$month,$day, $hour,$min,$sec) =
      Add_Delta_DHMS(1900,1,1, 0,0,0, $Dd,$Dh,$Dm,$Ds);

  printf(&quot;The given date is %s %02d:%02d:%02d\n&quot;,
      Date_to_Text($year,$month,$day), $hour, $min, $sec);</code></pre>

<p>This prints:</p>

<pre><code>  The given date is Tue 31-Mar-1998 12:16:53</code></pre>

<p>Since I do not have or use Visual Basic, I can&#39;t guarantee that the number format assumed here is really the one used by Visual Basic - but you get the general idea. <code>:-)</code></p>

<p>Moreover, consider the following:</p>

<p>Morten Sickel &lt;Morten.Sickel@nrpa.no&gt; wrote:</p>

<p>I discovered a bug in Excel (2000): Excel thinks that 1900 was a leap year. Users should use 31-Dec-1899 as the date to add an Excel date value to in order to get the correct date.</p>

<p>I found out on the web that this bug originated in Lotus 123, which made 29-Feb-1900 an &quot;industrial standard&quot;. MS chose to keep the bug in order to be compatible with Lotus 123. But they have not mentioned anything about it in the help files.</p>

</dd>
<dt id="12)"><a id="12"></a><a id="pod11"></a>12)</dt>
<dd>

<p>How can I send a reminder to members of a group on the day before a meeting which occurs every first Friday of a month?</p>

<pre><code>  use Date::Pcalc qw( Today Date_to_Days Add_Delta_YMD
                      Nth_Weekday_of_Month_Year );

  ($year,$month,$day) = Today();

  $tomorrow = Date_to_Days($year,$month,$day) + 1;

  $dow = 5; # 5 = Friday
  $n   = 1; # 1 = First of that day of week

  $meeting_this_month = Date_to_Days(
      Nth_Weekday_of_Month_Year($year,$month,$dow,$n) );

  ($year,$month,$day) = Add_Delta_YMD($year,$month,$day, 0,1,0);

  $meeting_next_month = Date_to_Days(
      Nth_Weekday_of_Month_Year($year,$month,$dow,$n) );

  if (($tomorrow == $meeting_this_month) ||
      ($tomorrow == $meeting_next_month))
  {
      # Send reminder e-mail!
  }</code></pre>

</dd>
<dt id="13)"><a id="13"></a><a id="pod12"></a>13)</dt>
<dd>

<p>How can I print a date in a different format than provided by the functions &quot;<code>Date_to_Text()</code>&quot;, &quot;<code>Date_to_Text_Long()</code>&quot; or &quot;<code>Compressed_to_Text()</code>&quot;?</p>

<pre><code>  use Date::Pcalc qw( Today Day_of_Week_to_Text
                      Day_of_Week Month_to_Text
                      English_Ordinal );

  ($year,$month,$day) = Today();</code></pre>

<p>For example with leading zeros for the day: &quot;<span style="white-space: nowrap;">Fri 03-Jan-1964</span>&quot;</p>

<pre><code>  printf(&quot;%.3s %02d-%.3s-%d\n&quot;,
      Day_of_Week_to_Text(Day_of_Week($year,$month,$day)),
      $day,
      Month_to_Text($month),
      $year);</code></pre>

<p>For example in U.S. american format: &quot;<span style="white-space: nowrap;">April 12th, 1998</span>&quot;</p>

<pre><code>  $string = sprintf(&quot;%s %s, %d&quot;,
                Month_to_Text($month),
                English_Ordinal($day),
                $year);</code></pre>

<p>For example in one of the possible formats as specified by <span style="white-space: nowrap;">ISO 8601</span>:</p>

<pre><code>  @date = ($year,$month,$day,$hour,$min,$sec);
  $date = sprintf(&quot;%d-%02d-%02d %02d:%02d:%02d&quot;, @date);</code></pre>

<p>(See also <a href="http://man.he.net/man1/perlfunc">&quot;printf&quot; in perlfunc(1)</a> and/or <a href="http://man.he.net/man1/perlfunc">&quot;sprintf&quot; in perlfunc(1)</a>!)</p>

</dd>
<dt id="14)"><a id="14"></a><a id="pod13"></a>14)</dt>
<dd>

<p>How can I iterate through a range of dates?</p>

<pre><code>  use Date::Pcalc qw( Delta_Days Add_Delta_Days );

  @start = (1999,5,27);
  @stop  = (1999,6,1);

  $j = Delta_Days(@start,@stop);

  for ( $i = 0; $i &lt;= $j; $i++ )
  {
      @date = Add_Delta_Days(@start,$i);
      printf(&quot;%4d/%02d/%02d\n&quot;, @date);
  }</code></pre>

<p>Note that the loop can be improved; see also the recipe below.</p>

</dd>
<dt id="15)"><a id="15"></a><a id="pod14"></a>15)</dt>
<dd>

<p>How can I create a (Perl) list of dates in a certain range?</p>

<pre><code>  use Date::Pcalc qw( Delta_Days Add_Delta_Days Date_to_Text );

  sub date_range
  {
      my(@date) = (@_)[0,1,2];
      my(@list);
      my($i);

      $i = Delta_Days(@_);
      while ($i-- &gt;= 0)
      {
          push( @list, [ @date ] );
          @date = Add_Delta_Days(@date, 1) if ($i &gt;= 0);
      }
      return(@list);
  }

  @range = &amp;date_range(1999,11,3, 1999,12,24); # in chronological order

  foreach $date (@range)
  {
      print Date_to_Text(@{$date}), &quot;\n&quot;;
  }</code></pre>

<p>Note that you probably shouldn&#39;t use this one, because it is much more efficient to iterate through all the dates (as shown in the recipe immediately above) than to construct such an array and then to loop through it. Also, it is much more space-efficient not to create this array.</p>

</dd>
<dt id="16)"><a id="16"></a><a id="pod15"></a>16)</dt>
<dd>

<p>How can I calculate the difference in days between dates, but without counting Saturdays and Sundays?</p>

<pre><code>  sub Delta_Business_Days
  {
      my(@date1) = (@_)[0,1,2];
      my(@date2) = (@_)[3,4,5];
      my($minus,$result,$dow1,$dow2,$diff,$temp);

      $minus  = 0;
      $result = Delta_Days(@date1,@date2);
      if ($result != 0)
      {
          if ($result &lt; 0)
          {
              $minus = 1;
              $result = -$result;
              $dow1 = Day_of_Week(@date2);
              $dow2 = Day_of_Week(@date1);
          }
          else
          {
              $dow1 = Day_of_Week(@date1);
              $dow2 = Day_of_Week(@date2);
          }
          $diff = $dow2 - $dow1;
          $temp = $result;
          if ($diff != 0)
          {
              if ($diff &lt; 0)
              {
                  $diff += 7;
              }
              $temp -= $diff;
              $dow1 += $diff;
              if ($dow1 &gt; 6)
              {
                  $result--;
                  if ($dow1 &gt; 7)
                  {
                      $result--;
                  }
              }
          }
          if ($temp != 0)
          {
              $temp /= 7;
              $result -= ($temp &lt;&lt; 1);
          }
      }
      if ($minus) { return -$result; }
      else        { return  $result; }
  }</code></pre>

<p>This solution is probably of little practical value, however, because it doesn&#39;t take legal holidays into account.</p>

<p>See <a href="http://man.he.net/man3/Date::Pcalendar">Date::Pcalendar(3)</a> for how to do that.</p>

</dd>
<dt id="17)"><a id="17"></a><a id="pod16"></a>17)</dt>
<dd>

<p>How can I &quot;normalize&quot; the output of the &quot;Delta_YMDHMS()&quot; (or &quot;Delta_YMD()&quot;) function so that it contains only positive values?</p>

<p>I.e., how can I show a difference in date (and time) in a more human-readable form, for example in order to show how much time until (or since) the expiration of something (e.g. an account, a domain, a credit card, etc.) is left (has passed)?</p>

<p>Correct solution: Use the functions &quot;N_Delta_YMDHMS()&quot; and &quot;N_Delta_YMD()&quot; instead!</p>

<p>The following gives a rudimentary sketch of a (much inferior) solution, which is maintained here only for historical reasons of this module:</p>

<p>a) Delta_YMDHMS():</p>

<pre><code>  #!perl
  use strict;
  use Date::Pcalc qw(Today_and_Now Delta_YMDHMS Add_Delta_YMDHMS Delta_DHMS Date_to_Text);

  my $today = [Today_and_Now()];
  my $target = [2005,1,1,0,0,0];

  my $sign = &quot;until&quot;;
  my $delta = Normalize_Delta_YMDHMS($today,$target);
  if ($delta-&gt;[0] &lt; 0)
  {
      $sign = &quot;since&quot;;
      $delta = Normalize_Delta_YMDHMS($target,$today);
  }
  printf(&quot;Today is %s %02d:%02d:%02d\n&quot;, Date_to_Text(@{$today}[0..2]), @{$today}[3..5]);
  printf
  (
      &quot;%d year%s, %d month%s, %d day%s, %d hour%s, %d minute%s, %d second%s %s %s %02d:%02d:%02d\n&quot;,
      $delta-&gt;[0], (($delta-&gt;[0]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[1], (($delta-&gt;[1]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[2], (($delta-&gt;[2]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[3], (($delta-&gt;[3]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[4], (($delta-&gt;[4]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[5], (($delta-&gt;[5]==1)?&#39;&#39;:&#39;s&#39;),
      $sign,
      Date_to_Text(@{$target}[0..2]),
      @{$target}[3..5]
  );

  sub Normalize_Delta_YMDHMS
  {
      my($date1,$date2) = @_;
      my(@delta);

      @delta = Delta_YMDHMS(@$date1,@$date2);
      while ($delta[1] &lt; 0 or
             $delta[2] &lt; 0 or
             $delta[3] &lt; 0 or
             $delta[4] &lt; 0 or
             $delta[5] &lt; 0)
      {
          if ($delta[1] &lt; 0) { $delta[0]--; $delta[1] += 12; }
          if ($delta[2] &lt; 0)
          {
              $delta[1]--;
              @delta[2..5] = (0,0,0,0);
              @delta[2..5] = Delta_DHMS(Add_Delta_YMDHMS(@$date1,@delta),@$date2);
          }
          if ($delta[3] &lt; 0) { $delta[2]--; $delta[3] += 24; }
          if ($delta[4] &lt; 0) { $delta[3]--; $delta[4] += 60; }
          if ($delta[5] &lt; 0) { $delta[4]--; $delta[5] += 60; }
      }
      return \@delta;
  }</code></pre>

<p>b) Delta_YMD():</p>

<pre><code>  #!perl
  use strict;
  use Date::Pcalc qw(Today Delta_YMD Add_Delta_YM Delta_Days Date_to_Text);

  my($sign,$delta);
  my $today = [Today()];
  my $target = [2005,1,1];

  if (Delta_Days(@$today,@$target) &lt; 0)
  {
      $sign = &quot;since&quot;;
      $delta = Normalize_Delta_YMD($target,$today);
  }
  else
  {
      $sign = &quot;until&quot;;
      $delta = Normalize_Delta_YMD($today,$target);
  }
  print &quot;Today is &quot;, Date_to_Text(@$today), &quot;\n&quot;;
  printf
  (
      &quot;%d year%s, %d month%s, %d day%s %s %s\n&quot;,
      $delta-&gt;[0], (($delta-&gt;[0]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[1], (($delta-&gt;[1]==1)?&#39;&#39;:&#39;s&#39;),
      $delta-&gt;[2], (($delta-&gt;[2]==1)?&#39;&#39;:&#39;s&#39;),
      $sign,
      Date_to_Text(@$target)
  );

  sub Normalize_Delta_YMD
  {
      my($date1,$date2) = @_;
      my(@delta);

      @delta = Delta_YMD(@$date1,@$date2);
      while ($delta[1] &lt; 0 or $delta[2] &lt; 0)
      {
          if ($delta[1] &lt; 0) { $delta[0]--; $delta[1] += 12; }
          if ($delta[2] &lt; 0)
          {
              $delta[1]--;
              $delta[2] = Delta_Days(Add_Delta_YM(@$date1,@delta[0,1]),@$date2);
          }
      }
      return \@delta;
  }</code></pre>

<p>Note that for normalizing just a time vector, you can use the built-in function &quot;Normalize_DHMS()&quot;. However, this will yield either all positive <b>OR</b> all negative values, <b>NOT</b> all positive values as above.</p>

</dd>
</dl>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<p>Date::Calc(3), Date::Calc::Util(3), Date::Pcalc::Object(3), Date::Pcalendar(3), Date::Pcalendar::Year(3), Date::Pcalendar::Profiles(3).</p>

<pre><code>  &quot;The Calendar FAQ&quot;:
  http://www.tondering.dk/claus/calendar.html
  by Claus Tondering &lt;claus@tondering.dk&gt;</code></pre>

<h1 id="BEWARE">BEWARE</h1>

<p>When you are using the (deprecated) function &quot;Language()&quot;, the language setting is stored in a global variable.</p>

<p>This may cause conflicts between threads or modules running concurrently.</p>

<p>Therefore, in order to avoid such conflicts, NEVER use the function &quot;Language()&quot;, but ALWAYS pass a language parameter to the functions which are language-dependent.</p>

<h1 id="VERSION">VERSION</h1>

<p>This man page documents &quot;Date::Pcalc&quot; version 6.1.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<pre><code>  Steffen Beyer
  mailto:STBEY@cpan.org
  http://www.engelschall.com/u/sb/download/</code></pre>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright (c) 1995 - 2009 by Steffen Beyer. All rights reserved.</p>

<h1 id="LICENSE">LICENSE</h1>

<p>This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the &quot;Artistic License&quot; or the &quot;GNU General Public License&quot;.</p>

<p>Please refer to the files &quot;Artistic.txt&quot; and &quot;GNU_GPL.txt&quot; in this distribution for details!</p>

<h1 id="DISCLAIMER">DISCLAIMER</h1>

<p>This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</p>

<p>See the &quot;GNU General Public License&quot; for more details.</p>

<div class="pod-errors"><p>1 POD Error</p><div class="pod-errors-detail"><p>The following errors were encountered while parsing the POD:</p><dl><dt>Around line 1777:</dt><dd><p>Non-ASCII character seen before =encoding in &#39;Fran&ccedil;ais&#39;. Assuming CP1252</p></dd></dl></div></div></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Date::Pcalc, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Date::Pcalc</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Date::Pcalc</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Date::Pcalc.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
